# check to see if termcolor is installed, we need it for color to work
try:
fromtermcolorimportcolored
@ -21,35 +18,14 @@ except ImportError:
exit()
ifdebug==1:
print("termcolor is installed!")
# If we are on Windows, we need to do a little more to get color to work
ifplatform.system()=='Windows':
os.system('color')
# ArgSparce
parser=argparse.ArgumentParser()
parser.add_argument("-s","--setup",help="Explains how to setup .txt file",action="store_true")
parser.add_argument("-c","--story",type=int,help="Write story count to file")
args=parser.parse_args()
# convert the integer to a string because pickiness
StoryCount=str(args.story)
#if statements for ArgSparce
# line 36 fails if args.story reads as "None", so we need to clear that string if it reads as such.
ifargs.story==None:
exec('args.story = int(0)')
# args.story should now read as 0
ifargs.story>0:
f=open('storyCount.txt',"r+")
IntStoryCount=f.read()
print("There are currently",IntStoryCount,"in stories.txt")
f.seek(0)
f.write(StoryCount)
f.close()
print("Writing",StoryCount,"to txt file!")
exit()
ifargs.setup==True:
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
# ArgsParce
defArgsParce():
parser=argparse.ArgumentParser()
parser.add_argument("-s","--setup",help="Explains how to setup .txt file",action="store_true")
args=parser.parse_args()
ifargs.setup==True:
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.")
ArgsParce()
ifplatform.system()=='Linux':
print('Linux master race! XD')
# Introduce yourself
@ -68,16 +44,15 @@ storyContentStr = []
storyNameStr=[]
# Alright, let's get the data from stories.txt
i=1
f=open('stories.txt','r')
forlineinf.readlines():
ifi%2==0:
storyContent=line
storyContentStr.append(storyContent)
else:
storyName=line
storyNameStr.append(storyName)
i+=1
f.close()
withopen('stories.txt','r')asf:
forlineinf:
ifi%2==0:
storyContent=line
storyContentStr.append(storyContent.rstrip())
else:
storyName=line
storyNameStr.append(storyName.rstrip())
i+=1
IntStoryCount=len(storyNameStr)
print("Detected",int(IntStoryCount),"stories")
# Randomly pick what story we will use
@ -85,7 +60,6 @@ story = random.randint(1, IntStoryCount)
print(storyNameStr)
# Print current story title, but remove the brackets first
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.
Once upon a time, there were three a pigs. One day, their mother said, "You are all grown up and must a on your own." So they left to a their houses. The first little pig wanted only to a all day and quickly built his house out of a. The second little pig wanted to a and a all day so he a his house with a. The third a pig knew the wolf lived nearby and worked hard to a his house out of a. One day, the wolf knocked on the first pig's a. "Let me in or I'll a your house down!" The pig didn't, so the wolf a down the a. The wolf knocked on the second pig's a. "Let me in or I'll blow your aa down!" The pig didn't, so the wolf a down the house. Then the wolf knocked on the third a pig's door. "Let me in or I'll blow your house down!" The little pig didn't, so the wolf a and a.He could not blow the house down. All the pigs went to live in the a house and they all a happily ever after.