From 889c5b1029503fb249662c2d66e3cf13c5d7aad6 Mon Sep 17 00:00:00 2001 From: crunk Date: Sun, 1 Mar 2020 15:56:39 +0100 Subject: [PATCH] made simplest poetry generator for just one line --- poetry.py | 18 +++++++++++++++++- start.py | 3 ++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/poetry.py b/poetry.py index 203d630..0c9d961 100644 --- a/poetry.py +++ b/poetry.py @@ -1,3 +1,4 @@ +import random def poetry(): filename = '2013_Wages_for_Facebook_[EN].txt' path = './manifestos/'+filename @@ -6,7 +7,22 @@ def poetry(): manifesto = manifesto.replace('\n', ' ') manifesto = manifesto.lower() 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 if __name__ == '__main__': diff --git a/start.py b/start.py index 98a488b..248f669 100644 --- a/start.py +++ b/start.py @@ -35,7 +35,8 @@ def index_words(): @APP.route('/poetry') def create_poetry(): - return render_template('poetry.html') + result = poetry() + return render_template('poetry.html', result=result) if __name__ == '__main__': APP.debug=True