#!/usr/bin/env python3 import json, requests, datetime, argparse, pytz, flask import library, forms app = flask.Flask(__name__) app.config['SECRET_KEY'] = "hunter2" @app.route('/', methods=('GET','POST')) def index(): form = forms.WeatherForm() if form.validate_on_submit(): location = form.location.data days = form.days.data forecast_type = form.forecast_type.data print(location) print(days) print(forecast_type) if forecast_type == 'hourly': return flask.redirect(flask.url_for('hourly', location=location, days=days)) elif forecast_type == 'daily': return flask.redirect(flask.url_for('daily', location=location, days=days)) return flask.render_template("index.html", form=form) @app.route('/hourly') def hourly(): location = flask.request.args.get('location', type=str) days = flask.request.args.get('days', type=int) latitude, longitude = library.get_lat_long(location) grid_data = library.get_grid_data(latitude, longitude) raw_data = library.get_raw_data(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"]) data = library.hourly_forecast(raw_data, days) return flask.render_template("hourly.html", data=data) @app.route('/daily') def daily(): location = flask.request.args.get('location', type=str) days = flask.request.args.get('days', type=int) latitude, longitude = library.get_lat_long(location) grid_data = library.get_grid_data(latitude, longitude) raw_data = library.get_raw_data(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"]) raw_forecast = library.get_raw_forecast(grid_data["grid_id"], grid_data["grid_x"], grid_data["grid_y"]) data = library.daily_forecast(raw_data, raw_forecast, days) return flask.render_template("daily.html", data=data)