Browse Source

made simplest poetry generator for just one line

master
crunk 5 years ago
parent
commit
889c5b1029
  1. 18
      poetry.py
  2. 3
      start.py

18
poetry.py

@ -1,3 +1,4 @@
import random
def poetry(): def poetry():
filename = '2013_Wages_for_Facebook_[EN].txt' filename = '2013_Wages_for_Facebook_[EN].txt'
path = './manifestos/'+filename path = './manifestos/'+filename
@ -6,7 +7,22 @@ def poetry():
manifesto = manifesto.replace('\n', ' ') manifesto = manifesto.replace('\n', ' ')
manifesto = manifesto.lower() manifesto = manifesto.lower()
words = manifesto.split(' ') words = manifesto.split(' ')
# Divide words into three lists
shortwords = []
mediumwords = []
longwords = []
for word in words:
if len(word) < 4:
shortwords.append(word)
elif 4 <= len(word) <= 7:
mediumwords.append(word)
else:
longwords.append(word)
print(shortwords)
line = (random.choice(shortwords),
random.choice(mediumwords),
random.choice(longwords))
result = " ".join(line)
return result return result
if __name__ == '__main__': if __name__ == '__main__':

3
start.py

@ -35,7 +35,8 @@ def index_words():
@APP.route('/poetry') @APP.route('/poetry')
def create_poetry(): def create_poetry():
return render_template('poetry.html') result = poetry()
return render_template('poetry.html', result=result)
if __name__ == '__main__': if __name__ == '__main__':
APP.debug=True APP.debug=True

Loading…
Cancel
Save