-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.py
93 lines (72 loc) · 2.78 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
import argparse
import json
import numpy as np
import pandas as pd
from flask import Flask, render_template, request, redirect, send_file
from flask_talisman import Talisman
from plots.climate import get_PM25_plot, get_NO2_plot, get_PM25_plot_diff, get_NO2_plot_diff
from plots.dark import get_cases_plot, get_deaths_plot
from plots.finance import get_finance_plot
import config
parser = argparse.ArgumentParser()
parser.add_argument("--host")
parser.add_argument("--port")
app = Flask(__name__)
talisman = Talisman(app, content_security_policy=None)
cases_data_update_date = os.environ.get('CASES_DATA_UPDATE_DATE', config.CASES_DATA_UPDATE_DATE)
climate_data_update_date = os.environ.get('CLIMATE_DATA_UPDATE_DATE', config.CLIMATE_DATA_UPDATE_DATE)
# Home page
@app.route('/')
def home():
return render_template("index.html")
@app.route('/contact')
def contact():
return render_template("contact.html")
@app.route('/dark/cases')
def cases_confirmed():
script, div = get_cases_plot()
return render_template("dark.html", script=script, div=div, date=cases_data_update_date, toggle=True)
@app.route('/dark/deaths')
def cases_deaths():
script, div = get_deaths_plot()
return render_template("dark.html", script=script, div=div, date=cases_data_update_date, toggle=False)
# NO2 page
@app.route('/NO2')
def climate_no2():
script, div = get_NO2_plot()
return render_template("climate.html", script=script, div=div, date=climate_data_update_date, toggle=1)
# PM25 page
@app.route('/PM25')
def climate_pm25():
script, div = get_PM25_plot()
return render_template("climate.html", script=script, div=div, date=climate_data_update_date, toggle=0)
# 2019 NO2 page
@app.route('/NO2_19')
def climate_no2_19():
script, div = get_NO2_plot_diff()
return render_template("climate.html", script=script, div=div, date=climate_data_update_date, toggle=3)
# 2019 PM25 page
@app.route('/PM25_19')
def climate_pm25_19():
script, div = get_PM25_plot_diff()
return render_template("climate.html", script=script, div=div, date=climate_data_update_date, toggle=2)
# 2019 NO2 page
@app.route('/finance')
def finance():
script, div = get_finance_plot()
return render_template("finance.html", script=script, div=div, date=climate_data_update_date, toggle=3)
@app.route('/download/<int:idx>')
def downloadFile(idx):
dir_path = os.path.dirname(os.path.realpath(__file__))
data_dir = os.path.join(dir_path, "data")
if idx < 2:
path = os.path.join(data_dir, "aqi_df.csv")
return send_file(path, as_attachment=True)
else:
path = os.path.join(data_dir, "aqi_df_diff.csv")
return send_file(path, as_attachment=True)
if __name__ == '__main__':
args = parser.parse_args()
#app.run(debug=True)
app.run(host=args.host, port=args.port)