-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
57 lines (46 loc) · 1.06 KB
/
main.py
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
from pprint import pprint as pp
from flask import (
Flask,
flash,
redirect,
render_template,
request,
url_for
)
from weather import query_api
app = Flask(__name__)
@app.route('/')
def index():
return render_template(
'weather.html',
data=[
{'name': 'Toronto'},
{'name': 'Montreal'},
{'name': 'Calgary'},
{'name': 'Ottawa'},
{'name': 'Edmonton'},
{'name': 'Mississauga'},
{'name': 'Winnipeg'},
{'name': 'Vancouver'},
{'name': 'Brampton'},
{'name': 'Quebec'}
]
)
@app.route('/result', methods=['GET', 'POST'])
def result():
data = []
error = None
select = request.form.get('comp_select')
resp = query_api(select)
pp(resp)
if resp:
data.append(resp)
if len(data) != 2:
error = 'Bad Response from Weather API'
return render_template(
'result.html',
data=data,
error=error
)
if __name__ == '__main__':
app.run(debug=True)