diff options
Diffstat (limited to 'app.py')
| -rw-r--r-- | app.py | 42 |
1 files changed, 14 insertions, 28 deletions
| @@ -10,36 +10,22 @@ def index(): | |||
| 10 | form = forms.WeatherForm() | 10 | form = forms.WeatherForm() |
| 11 | if form.validate_on_submit(): | 11 | if form.validate_on_submit(): |
| 12 | location = form.location.data | 12 | location = form.location.data |
| 13 | days = form.days.data | 13 | return flask.redirect(flask.url_for('weather', location=location)) |
| 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) | 14 | return flask.render_template("index.html", form=form) |
| 24 | 15 | ||
| 25 | @app.route('/hourly') | ||
| 26 | def 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 | 16 | ||
| 36 | @app.route('/daily') | 17 | @app.route('/weather', methods=('GET','POST')) |
| 37 | def daily(): | 18 | def weather(): |
| 38 | location = flask.request.args.get('location', type=str) | 19 | 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) | 20 | latitude, longitude = library.get_lat_long(location) |
| 41 | grid_data = library.get_grid_data(latitude, longitude) | 21 | data = library.get_data(latitude, longitude) |
| 42 | raw_data = library.get_raw_data(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"]) | 22 | hour = library.get_current_rounded_time(data["timezone"]).hour |
| 43 | raw_forecast = library.get_raw_forecast(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"]) | 23 | form = forms.WeatherForm() |
| 44 | data = library.daily_forecast(raw_data, raw_forecast, days) | 24 | if form.validate_on_submit(): |
| 45 | return flask.render_template("daily.html", data=data) | 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() | ||
