|
70 | 70 | # Randomly pick what story we will use |
71 | 71 | story = random.randint(1, IntStoryCount) |
72 | 72 |
|
| 73 | +#Declare vars |
| 74 | +storyContentStr = [] |
| 75 | +storyNameStr = [] |
73 | 76 | # Alright, let's get the data from stories.txt |
74 | 77 | i = 1 |
75 | 78 | f = open('stories.txt', 'r') |
76 | 79 | for line in f.readlines(): |
77 | 80 | if i % 2 == 0 : |
78 | 81 | storyContent = line |
| 82 | + storyContentStr.append(storyContent) |
79 | 83 | else: |
80 | 84 | storyName = line |
| 85 | + storyNameStr.append(storyName) |
81 | 86 | i+=1 |
82 | 87 | f.close() |
| 88 | +print(storyNameStr) |
83 | 89 | # Print current story title, but remove the brackets first |
84 | | -filteredTitle = re.findall(r'<(.*?)>', storyName) |
| 90 | +filteredTitle = re.findall(r'<(.*?)>', storyNameStr[story-1]) |
| 91 | + |
85 | 92 | # print the first result |
86 | 93 | print("Current story title is", '"'+filteredTitle[0]+'"','\n') |
87 | | - |
88 | 94 | # Alright, now onto the tricky part. We need to filter out all of the bracketed words in stories.txt, putting them into a list, replacing them with incremental strings. We also need to count how many there are for later. |
89 | 95 | # Pull all of the items with the <> brackets |
90 | | -filtered = re.findall(r'<(.*?)>', storyContent) |
| 96 | +filtered = re.findall(r'<(.*?)>', storyContentStr[story-1]) |
91 | 97 | # We got them! |
92 | 98 | if debug == 1: |
93 | 99 | print(filtered, '\n') |
|
110 | 116 | print("Replacing Words...") |
111 | 117 |
|
112 | 118 | # Split the Story Content into a list |
113 | | -storyContentList = re.split(r'<.*?>', storyContent) |
| 119 | +storyContentList = re.split(r'<.*?>', storyContentStr[story-1]) |
114 | 120 | # Count the items in the list |
115 | 121 | storyContentCount = len(storyContentList) |
116 | 122 | x = 0 |
|
121 | 127 | # To get colored words for our output, we need to add the appropiate commands to our variable. |
122 | 128 | storyContentListColored = re.split(r'<.*?>', storyContent) |
123 | 129 | x = 0 |
124 | | -#for loopCount in range(storyContentCount): |
125 | | -# #print(storyContentList[loopCount]) |
126 | | -# storyContentListColored[x-1] = '\"'+re.escape(storyContentListColored[x-1])+'\"' |
127 | | -# storyContentListColored.insert(x, "colored(\'"+replaceList[loopCount]+"\', '"\'+blue+"\""),") |
128 | | -# x = x+2 |
129 | | -#print(storyContentListColored) |
130 | | -#print('\n') |
| 130 | + |
131 | 131 | # Merge lists into a string |
132 | 132 | generatedStory = "" |
133 | 133 | generatedStory = generatedStory.join(storyContentList) |
134 | | -# for the colored printout... |
135 | | -#generatedStoryColored = "" |
136 | | -#generatedStoryColored = generatedStoryColored.join(storyContentListColored) |
137 | | -#print(generatedStoryColored) |
| 134 | + |
138 | 135 | print(generatedStory) |
139 | | -#print(exec(generatedStoryColored)) |
140 | 136 | #exit() |
141 | 137 | #Alright! We're done! Let's save the story to a file |
142 | 138 | now = datetime.now() |
|
147 | 143 | os.system("mkdir \"saved stories\"") |
148 | 144 |
|
149 | 145 | currentDate = now.strftime("%d-%m-%Y-%H:%M:%S") |
150 | | -saveFile = 'saved stories/generatedStory-'+currentDate+'.txt' |
| 146 | +saveFile = 'saved stories/generatedStory-'+currentDate |
151 | 147 | print("Saving story to .txt file") |
152 | | -file = open(saveFile, 'w+') |
| 148 | +file = open(saveFile+'.txt', 'w+') |
153 | 149 |
|
154 | 150 | line_offset = [] |
155 | 151 | offset = 0 |
|
167 | 163 | print('\n'+"Processing Text-To-Speech, please wait..."+'\n') |
168 | 164 | tts = gTTS(text=generatedStory, lang='en') |
169 | 165 | tts.save("TTS.mp3") |
170 | | -#os.system("play TTS.mp3") |
171 | | -os.system("cp TTS.mp3 \"saved stories\\"") |
| 166 | +os.system("play TTS.mp3") |
| 167 | +os.system("mv TTS.mp3 "+saveFile+".mp3\"") |
172 | 168 |
|
173 | 169 |
|
0 commit comments