-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
54 lines (45 loc) · 1.48 KB
/
app.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
import sqlite3
from flask import (
Flask, request, session, g, redirect, url_for, abort,
render_template, flash, send_file)
from contextlib import closing
from custom.weather import Weather
# Configuration
DEBUG = True
SECRET_KEY = 'development key'
USERNAME = 'admin'
PASSWORD = 'default'
DOWNLOAD_FOLDER = 'data/'
app = Flask(__name__)
app.config.from_object(__name__)
@app.route('/')
def show_entries():
return render_template('show_entries.html')
@app.route('/weather', methods=['GET', 'POST'])
def show_weather():
error = None
weather = None
if request.method == 'POST':
w = Weather()
weather = w.getCurrentWeather(request.form['filter'])
if not weather:
error = 'Invalid city name'
return render_template('weather.html', error=error, weather = weather)
@app.route('/downloadfiles/<filename>')
def download_files(filename):
file_path = DOWNLOAD_FOLDER + filename
return send_file(file_path, as_attachment=True, attachment_filename='')
@app.route('/weather_visualization', methods=['GET', 'POST'])
def get_weather_forecast():
error = None
forecast = None
city = None
times = None
if request.method == 'POST':
city = request.form['filter']
forecast, times = Weather().forecast(city)
if not forecast:
error = 'Error fetching forecast'
return render_template('forecast.html', error=error, forecast = forecast, city=city, times=times)
if __name__ == '__main__':
app.run()