diff options
Diffstat (limited to 'app.py')
-rw-r--r-- | app.py | 31 |
1 files changed, 0 insertions, 31 deletions
@@ -1,31 +0,0 @@ | |||
1 | #!/usr/bin/env python3 | ||
2 | import json, requests, datetime, argparse, pytz, flask | ||
3 | import library, forms | ||
4 | |||
5 | app = flask.Flask(__name__) | ||
6 | app.config['SECRET_KEY'] = "hunter2" | ||
7 | |||
8 | @app.route('/', methods=('GET','POST')) | ||
9 | def index(): | ||
10 | form = forms.WeatherForm() | ||
11 | if form.validate_on_submit(): | ||
12 | location = form.location.data | ||
13 | return flask.redirect(flask.url_for('weather', location=location)) | ||
14 | return flask.render_template("index.html", form=form) | ||
15 | |||
16 | |||
17 | @app.route('/weather', methods=('GET','POST')) | ||
18 | def weather(): | ||
19 | location = flask.request.args.get('location', type=str) | ||
20 | latitude, longitude = library.get_lat_long(location) | ||
21 | data = library.get_data(latitude, longitude) | ||
22 | hour = library.get_current_rounded_time(data["timezone"]).hour | ||
23 | form = forms.WeatherForm() | ||
24 | if form.validate_on_submit(): | ||
25 | location = form.location.data | ||
26 | return flask.redirect(flask.url_for('weather', location=location)) | ||
27 | return flask.render_template("weather.html", data=data, form=form, weather_codes=library.weather_codes, | ||
28 | weather_icons=library.weather_icons, hour=hour) | ||
29 | |||
30 | if __name__ == "__main__": | ||
31 | app.run() | ||