Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit caaa14a

Browse files
Caleb FontenotCaleb Fontenot
authored andcommitted
Fixed Story Randomizer, added more of Torys stories
1 parent a365098 commit caaa14a

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

madlibs/TTS.mp3

44.5 KB
Binary file not shown.

madlibs/madlibs.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,30 @@
7070
# Randomly pick what story we will use
7171
story = random.randint(1, IntStoryCount)
7272

73+
#Declare vars
74+
storyContentStr = []
75+
storyNameStr = []
7376
# Alright, let's get the data from stories.txt
7477
i = 1
7578
f = open('stories.txt', 'r')
7679
for line in f.readlines():
7780
if i % 2 == 0 :
7881
storyContent = line
82+
storyContentStr.append(storyContent)
7983
else:
8084
storyName = line
85+
storyNameStr.append(storyName)
8186
i+=1
8287
f.close()
88+
print(storyNameStr)
8389
# Print current story title, but remove the brackets first
84-
filteredTitle = re.findall(r'<(.*?)>', storyName)
90+
filteredTitle = re.findall(r'<(.*?)>', storyNameStr[story-1])
91+
8592
# print the first result
8693
print("Current story title is", '"'+filteredTitle[0]+'"','\n')
87-
8894
# 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.
8995
# Pull all of the items with the <> brackets
90-
filtered = re.findall(r'<(.*?)>', storyContent)
96+
filtered = re.findall(r'<(.*?)>', storyContentStr[story-1])
9197
# We got them!
9298
if debug == 1:
9399
print(filtered, '\n')
@@ -110,7 +116,7 @@
110116
print("Replacing Words...")
111117

112118
# Split the Story Content into a list
113-
storyContentList = re.split(r'<.*?>', storyContent)
119+
storyContentList = re.split(r'<.*?>', storyContentStr[story-1])
114120
# Count the items in the list
115121
storyContentCount = len(storyContentList)
116122
x = 0
@@ -121,22 +127,12 @@
121127
# To get colored words for our output, we need to add the appropiate commands to our variable.
122128
storyContentListColored = re.split(r'<.*?>', storyContent)
123129
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+
131131
# Merge lists into a string
132132
generatedStory = ""
133133
generatedStory = generatedStory.join(storyContentList)
134-
# for the colored printout...
135-
#generatedStoryColored = ""
136-
#generatedStoryColored = generatedStoryColored.join(storyContentListColored)
137-
#print(generatedStoryColored)
134+
138135
print(generatedStory)
139-
#print(exec(generatedStoryColored))
140136
#exit()
141137
#Alright! We're done! Let's save the story to a file
142138
now = datetime.now()
@@ -147,9 +143,9 @@
147143
os.system("mkdir \"saved stories\"")
148144

149145
currentDate = now.strftime("%d-%m-%Y-%H:%M:%S")
150-
saveFile = 'saved stories/generatedStory-'+currentDate+'.txt'
146+
saveFile = 'saved stories/generatedStory-'+currentDate
151147
print("Saving story to .txt file")
152-
file = open(saveFile, 'w+')
148+
file = open(saveFile+'.txt', 'w+')
153149

154150
line_offset = []
155151
offset = 0
@@ -167,7 +163,7 @@
167163
print('\n'+"Processing Text-To-Speech, please wait..."+'\n')
168164
tts = gTTS(text=generatedStory, lang='en')
169165
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\"")
172168

173169

0 commit comments

Comments
 (0)