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.
40 lines
950 B
40 lines
950 B
6 years ago
|
#!/usr/bin/env python3
|
||
|
|
||
|
import os
|
||
|
import flask
|
||
|
from flask import request
|
||
|
import tfidf
|
||
|
|
||
|
def get_index():
|
||
|
index = tfidf.load_index()
|
||
|
return index
|
||
|
|
||
|
def get_results(query):
|
||
|
results, index = tfidf.request_results(query)
|
||
|
return results, index
|
||
|
|
||
|
# Create the application.
|
||
|
APP = flask.Flask(__name__)
|
||
|
|
||
|
@APP.route('/', methods=['GET', 'POST'])
|
||
|
def index():
|
||
|
""" Displays the index page accessible at '/'
|
||
|
"""
|
||
|
query = None
|
||
|
results = None
|
||
|
|
||
|
if request.args.get('q', ''):
|
||
|
query = request.args.get('q', '')
|
||
|
results, index = get_results(query)
|
||
|
files = [manifesto for manifesto, _ in index.items()]
|
||
|
return flask.render_template('results.html', query=query, results=results, files=files)
|
||
|
else:
|
||
|
index = get_index()
|
||
|
files = [manifesto for manifesto, _ in index.items()]
|
||
|
return flask.render_template('index.html', files=files)
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
if not 'index.json' in os.listdir('.'):
|
||
|
tfidf.create_index()
|
||
|
APP.debug=True
|
||
|
APP.run()
|