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