aboutsummaryrefslogtreecommitdiff
path: root/app.py
diff options
context:
space:
mode:
Diffstat (limited to 'app.py')
-rw-r--r--app.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/app.py b/app.py
new file mode 100644
index 0000000..e929032
--- /dev/null
+++ b/app.py
@@ -0,0 +1,45 @@
1#!/usr/bin/env python3
2import json, requests, datetime, argparse, pytz, flask
3import library, forms
4
5app = flask.Flask(__name__)
6app.config['SECRET_KEY'] = "hunter2"
7
8@app.route('/', methods=('GET','POST'))
9def index():
10 form = forms.WeatherForm()
11 if form.validate_on_submit():
12 location = form.location.data
13 days = form.days.data
14 forecast_type = form.forecast_type.data
15 print(location)
16 print(days)
17 print(forecast_type)
18 if forecast_type == 'hourly':
19 return flask.redirect(flask.url_for('hourly', location=location, days=days))
20 elif forecast_type == 'daily':
21 return flask.redirect(flask.url_for('daily', location=location, days=days))
22
23 return flask.render_template("index.html", form=form)
24
25@app.route('/hourly')
26def hourly():
27 location = flask.request.args.get('location', type=str)
28 days = flask.request.args.get('days', type=int)
29 latitude, longitude = library.get_lat_long(location)
30 grid_data = library.get_grid_data(latitude, longitude)
31 raw_data = library.get_raw_data(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"])
32 data = library.hourly_forecast(raw_data, days)
33 return flask.render_template("hourly.html", data=data)
34
35
36@app.route('/daily')
37def daily():
38 location = flask.request.args.get('location', type=str)
39 days = flask.request.args.get('days', type=int)
40 latitude, longitude = library.get_lat_long(location)
41 grid_data = library.get_grid_data(latitude, longitude)
42 raw_data = library.get_raw_data(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"])
43 raw_forecast = library.get_raw_forecast(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"])
44 data = library.daily_forecast(raw_data, raw_forecast, days)
45 return flask.render_template("daily.html", data=data)