Browse Source

Added words.py and poetry.py plus jinja templates

master
crunk 4 years ago
parent
commit
a85c9fc517
  1. 14
      poetry.py
  2. 2
      search.py
  3. 5
      start.py
  4. 2
      templates/manifesto.html
  5. 1
      templates/poetry.html
  6. 8
      templates/words.html
  7. 28
      words.py

14
poetry.py

@ -0,0 +1,14 @@
def poetry():
filename = '2013_Wages_for_Facebook_[EN].txt'
path = './manifestos/'+filename
file = open(path, 'r')
manifesto = file.read()
manifesto = manifesto.replace('\n', ' ')
manifesto = manifesto.lower()
words = manifesto.split(' ')
return result
if __name__ == '__main__':
result = poetry()
print('result:', result)

2
search.py

@ -20,7 +20,7 @@ def search(query):
return result
if __name__ == '__main__':
query = 'danny'
query = 'test'
result = search(query)
print('query:', query)
print('result:', result)

5
start.py

@ -3,6 +3,8 @@ import flask
from flask import request, render_template
from search import *
from poetry import *
from words import *
APP = flask.Flask(__name__)
@ -28,7 +30,8 @@ def search_manifesto():
@APP.route('/words')
def index_words():
return render_template('words.html')
countedwords = words()
return render_template('words.html', countedwords=countedwords)
@APP.route('/poetry')
def create_poetry():

2
templates/manifesto.html

@ -4,8 +4,6 @@
<h1>{{ filename }}</h1>
<!-- <div>{{ text }}</div> -->
{% for line in lines %}
<div>{{ line }}. </div>
{% endfor %}

1
templates/poetry.html

@ -2,4 +2,5 @@
{% block main %}
<h1>poetry</h1>
<p>{{ result }}</p>
{% endblock %}

8
templates/words.html

@ -2,4 +2,12 @@
{% block main %}
<h1>words</h1>
<table>
{% for key, value in countedwords.items() %}
<tr>
<td>{{ key }}</td>
<td>{{ value }}</td>
</tr>
{% endfor %}
</table>
{% endblock %}

28
words.py

@ -0,0 +1,28 @@
from collections import OrderedDict
from operator import itemgetter
def words():
filename = '2013_Wages_for_Facebook_[EN].txt'
path = './manifestos/'+filename
file = open(path, 'r')
manifesto = file.read()
manifesto = manifesto.replace('\n', ' ')
manifesto = manifesto.lower()
manifesto = manifesto.strip()
words = manifesto.split(' ')
new_dict = dict()
for word in words:
if word in new_dict:
# Present so add 1 to the count of word.
new_dict[word] = new_dict[word] + 1
else:
# Add the word to dictionary with count 1
new_dict[word] = 1
result = OrderedDict(sorted(new_dict.items(), key=itemgetter(1), reverse=True))
return result
if __name__ == '__main__':
result = words()
print('result:', result)
Loading…
Cancel
Save