You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.3 KiB
42 lines
1.3 KiB
#!/usr/bin/env python3
|
|
|
|
import os
|
|
import flask
|
|
|
|
import readings
|
|
from create_index import create_index
|
|
|
|
# Create the application.
|
|
APP = flask.Flask(__name__)
|
|
|
|
@APP.route('/', methods=['GET', 'POST'])
|
|
def index():
|
|
data, index = readings.get_pos()
|
|
filenames = [document for document, _ in index.items()]
|
|
return flask.render_template('index.html', data=data, filenames=filenames)
|
|
|
|
@APP.route('/<word_type>/<word>', methods=['GET', 'POST'])
|
|
def results(word_type, word):
|
|
data, index = readings.get_pos()
|
|
for ranking, words in data[word_type].items():
|
|
for w in words.keys():
|
|
if w == word:
|
|
results = data[word_type][ranking][word.lower()]
|
|
filenames = [document for document, _ in index.items()]
|
|
return flask.render_template('results.html', data=data, results=results, filenames=filenames, word=word, word_type=word_type)
|
|
|
|
@APP.route('/document/<name>', methods=['GET', 'POST'])
|
|
def open_document(name):
|
|
"""
|
|
Open document.
|
|
"""
|
|
data, index = readings.get_pos()
|
|
filenames = sorted([document for document, _ in index.items()])
|
|
txt = open('txt/{}.txt'.format(name), 'r').readlines()
|
|
return flask.render_template('document.html', data=data, name=name, filenames=filenames, txt=txt)
|
|
|
|
if __name__ == '__main__':
|
|
if not 'index.json' in os.listdir('.'):
|
|
create_index()
|
|
APP.debug=True
|
|
APP.run(port=5000)
|