a flask exercise and search machine prototype
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.

79 lines
2.1 KiB

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, files = tfidf.request_results(query)
return results, files
def get_ordered():
results, files = tfidf.request_ordered()
return results, files
def get_ordered_all():
results, files = tfidf.request_ordered_all()
return results, files
6 years ago
# 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, files = get_results(query)
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)
@APP.route('/lists', methods=['GET', 'POST'])
def lists():
""" Displays the index page accessible at '/lists'
"""
query = None
results = None
6 years ago
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_lists.html', query=query, results=results, files=files)
6 years ago
else:
index = get_index()
files = [manifesto for manifesto, _ in index.items()]
return flask.render_template('index.html', files=files)
@APP.route('/ordered', methods=['GET', 'POST'])
def ordered():
results, files = get_ordered()
return flask.render_template('ordered.html', files=files, results=results)
@APP.route('/ordered/all', methods=['GET', 'POST'])
def ordered_all():
results, files = get_ordered_all()
return flask.render_template('ordered.all.html', files=files, results=results)
# @APP.route('/ordered.all', methods=['GET', 'POST'])
# def ordered():
# results, files = get_ordered_all()
# return flask.render_template('ordered.all.html', files=files, results=results)
6 years ago
if __name__ == '__main__':
if not 'index.json' in os.listdir('.'):
tfidf.create_index()
APP.debug=True
APP.run()