-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebapp.py
More file actions
74 lines (57 loc) · 1.76 KB
/
webapp.py
File metadata and controls
74 lines (57 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import flask
from flask import render_template, request, redirect
import json
import sys
from datetime import datetime
from backend.datasource import DataSource
app = flask.Flask(__name__)
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
datasource = DataSource()
@app.route('/')
def home():
"""
Renders the home page of Restaurant Reviews in Mississauga.
Audience: all
RETURNS:
render Main_Page.html
"""
return render_template('Main_Page.html')
@app.route('/data')
def data_page():
"""
Renders the "About Data" page that includes metadata and description of the
entire dataset. There are also some example data on this page.
Audience: all
RETURNS:
render Data_Page.html
"""
return render_template('Data_Page.html')
@app.route('/advanced_search')
def advanced_search():
"""
Renders the advanced search page, a page with only search functionality.
RETURNS:
render Advanced_Search.html
"""
return render_template('Advanced_Search.html')
@app.route('/results', methods = ['POST'])
def results():
"""
Renders the results page with new info.
Audience: all
RETURNS:
render results.html
"""
queryName = request.form['query']
queryStars = request.form['stars']
datasource = DataSource()
listOfRestaurantNames = datasource.searchRestaurantsByNameAndMinimumStars(queryName, queryStars)
restaurants = datasource.generateRestaurantObjects(listOfRestaurantNames[:15])
return render_template('results.html', restaurants=restaurants)
if __name__ == '__main__':
if len(sys.argv) != 3:
print('Usage: {0} host port'.format(sys.argv[0]), file=sys.stderr)
exit()
host = sys.argv[1]
port = sys.argv[2]
app.run(host=host, port=port)