modified: madlibs.py

master
Chloe Fontenot 🏳️‍⚧️ 2019-07-15 12:44:30 +07:00
parent 63a1bafaa0
commit 9351749e9e
3 changed files with 53 additions and 27 deletions

@ -0,0 +1,3 @@
Once upon a time, there were three [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] pigs. One day, their mother said, "You are all grown up and must [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] on your own." So they left to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] their houses. The first little pig wanted only to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] all day and quickly built his house out of [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. The second little pig wanted to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] and [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] all day so he [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] his house with [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. The third [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] pig knew the wolf lived nearby and worked hard to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] his house out of [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. One day, the wolf knocked on the first pig's [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. "Let me in or I'll [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] your house down!" The pig didn't, so the wolf [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] down the [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. The wolf knocked on the second pig's [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. "Let me in or I'll blow your [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] down!" The pig didn't, so the wolf [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] down the house. Then the wolf knocked on the third [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] pig's door. "Let me in or I'll blow your house down!" The little pig didn't, so the wolf [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] and [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]].He could not blow the house down. All the pigs went to live in the [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] house and they all [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] happily ever after.
Generated by Caleb Fontenot's madlibs.pyOnce upon a time, there were three [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] pigs. One day, their mother said, "You are all grown up and must [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] on your own." So they left to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] their houses. The first little pig wanted only to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] all day and quickly built his house out of [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. The second little pig wanted to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] and [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] all day so he [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] his house with [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. The third [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] pig knew the wolf lived nearby and worked hard to [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] his house out of [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. One day, the wolf knocked on the first pig's [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. "Let me in or I'll [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] your house down!" The pig didn't, so the wolf [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] down the [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. The wolf knocked on the second pig's [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]]. "Let me in or I'll blow your [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] down!" The pig didn't, so the wolf [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] down the house. Then the wolf knocked on the third [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] pig's door. "Let me in or I'll blow your house down!" The little pig didn't, so the wolf [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] and [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]].He could not blow the house down. All the pigs went to live in the [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] house and they all [[...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...], [...]] happily ever after.
Generated by Caleb Fontenot's madlibs.py

@ -2,12 +2,13 @@
debug = 1
# Import the libraries we will use
import datetime
import re
import sys
import random
import platform
import argparse
# check to see if termcolor is installed, we need it for color to xwork
# check to see if termcolor is installed, we need it for color to work
try:
from termcolor import colored
except ImportError:
@ -29,18 +30,21 @@ StoryCount = str(args.story)
#if statements for ArgSparce
# line 35 fails if args.story reads as "None", so we need to clear that string if it reads as such.
# line 36 fails if args.story reads as "None", so we need to clear that string if it reads as such.
if args.story == None:
exec('args.story = int(0)')
# args.story should now read as 0
if args.story > 0:
f = open('storyCount.txt', 'w')
f = open('storyCount.txt', "r+")
IntStoryCount = f.read()
print("There are currently", IntStoryCount, "in stories.txt")
f.seek(0)
f.write(StoryCount)
f.close()
exit()
print("Writing", StoryCount, "to txt file!")
exit()
if args.setup == True:
sys.exit("If you want to include your own MadLibs story, you need to do the following:"+'\n')
sys.exit("If you want to include your own MadLibs story, you need to do the following:"+'\n'+"1. Open "+"\"stories.txt\""+'\n'+"2. Put the title of the story on all of the odd lines"+'\n'+"3. Put the entire story on one line, and put words you wish to replace in <>. Use the example as a reference."+'\n'+"4. When you are done, run me with the -c or --story flag to update how many stories are in stories.txt.")
# Linux easter egg
if platform.system() == 'Linux':
print('Linux master race! XD')
@ -59,38 +63,57 @@ f = open('storyCount.txt', 'r')
StoryCount = f.read()
IntStoryCount = int(StoryCount)
print("Detected", IntStoryCount, "stories")
# Count stories
# Randomly pick what story we will use
story = random.randint(1, IntStoryCount)
# Alright, let's get the data from stories.txt
i = 1
f = open('stories.txt', 'r')
# This pulls the title from stories.txt
storyName = f.readline()
# This pulls the story from stories.txt
storyContent = f.readline()
# todo: remove characters from story identifier and make every even number be recognized as a story, and every odd as it's title
# Hacky shenanigans
#selectedStoryName = storyName[story - 1]
# Print current story title
print("Current story title is", '"'+storyName+'"')
for line in f.readlines():
if i % 2 == 0 :
storyContent = line
else:
storyName = line
i+=1
f.close()
# Print current story title, but remove the brackets first
filteredTitle = re.findall(r'<(.*?)>', storyName)
# print the first result
print("Current story title is", '"'+filteredTitle[0]+'"','\n')
# 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.
# Pull all of the items with the <> brackets
filtered = re.findall(r'<.*?>', storyContent)
filteredReplaced = re.sub(r'<.*?>', storyContent)
filtered = re.findall(r'<(.*?)>', storyContent)
# We got them!
print(filtered)
if debug == 1:
print(filtered, '\n')
# Now we need to count them
replacedNumber = len(filtered)
print(replacedNumber)
# Run a loop to get the words
#This normally is just "replaceList = []"
replaceList = ['1', '2', '43', '', '2643', '62', '36', '236', '23', '6234', '623', '623', '46', '2346', '234', '6234', '623', '4', '234', '6234', '2346', '2345124', '12', '1']
#for loopCount in range(replacedNumber):
# replaceVar = input("Give me a(n) "+filtered[loopCount]+": ")
# replaceList.append(replaceVar)
print(replaceList)
# Run a loop to replace the words
print("Replacing Words...")
for loopCount in range(replacedNumber):
currentReplace = replaceList[loopCount]
print(re.finditer(r'<.*?>',storyContent))
print("Replacing", currentReplace)
filteredReplaced = re.sub(r'<.*?>',currentReplace, storyContent, loopCount)
print(filteredReplaced)
#This exit was intensional, just to prevent it from executing the rest of the program while I work on it...
exit()
currentDate1 = datetime.date
currentDate2 = str(currentDate1)
print("Saving story to .txt file")
f = open('generatedStory'+currentDate2+'.txt', 'a')
f.write(filteredReplaced)
f.seek(3)
f.write("Generated by Caleb Fontenot\'s madlibs.py")
f.close()