-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
389 lines (339 loc) · 14.2 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
import datetime as dt
import json
import uuid
import dash
import dash_core_components as dcc
import dash_html_components as html
import dash_table
import flask
from apscheduler.schedulers.background import BackgroundScheduler
from dash.dependencies import Input, Output
server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server, routes_pathname_prefix="/data/")
app.config.suppress_callback_exceptions = True
app.server.secret_key = str(uuid.uuid4())
from pages import (
countrycasesgrowth,
countryratechanges,
credit,
home,
indiahelpline,
indiatable,
livecoronamap,
livecoronatable,
liveindiamap,
liveusamap,
liveusatable,
prediction,
)
from refresh import update
from pages.functions import indiadata, worlddata
external_stylesheets = ["https://codepen.io/theajit/pen/vYYxVLb.css"]
# external JavaScript files
external_scripts = [
"https://codepen.io/theajit/pen/JjdLvZE.js",
]
app.title = "Track Corona India | USA | China | Online Live "
app.layout = html.Div(
[
dcc.Location(id="url", refresh=False),
html.Title("Track Corona India"),
html.Img(src=app.get_asset_url("track_corona_online_logo.png"), title="Track Corona Logo", style={
"height": "80px",
"textAlign": "center",
"display": "inline-block",
"margin-left": "1.5%",
"margin-top": "0.5%"
}),
html.Div(
[
html.Ul(
[
html.Li([dcc.Link("Home ", href="/")]),
html.Li(
[
dcc.Link("India", href="#"),
html.Ul(
[
html.Li(
[
dcc.Link(
"India Table ",
href="/data/live-india-table",
)
]
),
html.Li(
[
dcc.Link(
"India Map ",
href="/data/live-india-map",
)
]
),
html.Li(
[
html.A(
"India helpline ",
href="/data/india-helpline",
)
]
),
],
className="submenu",
),
]
),
html.Li(
[
dcc.Link("Live Table ", href="#"),
html.Ul(
[
html.Li(
[
dcc.Link(
"India Table ",
href="/data/live-india-table",
)
]
),
html.Li(
[
dcc.Link(
"World Table ",
href="/data/live-corona-world-table",
)
]
),
html.Li(
[
dcc.Link(
"USA Table ",
href="/data/live-corona-usa-table",
)
]
),
],
className="submenu",
),
]
),
html.Li(
[
dcc.Link("Live Map ", href="#"),
html.Ul(
[
html.Li(
[
dcc.Link(
"World Map ",
href="/data/live-corona-world-map",
)
]
),
html.Li(
[
dcc.Link(
"India Map ",
href="/data/live-india-map",
)
]
),
html.Li(
[
dcc.Link(
"USA Map ",
href="/data/live-corona-usa-map",
)
]
),
],
className="submenu",
),
]
),
html.Li(
[
dcc.Link("Case Analysis ", href="#"),
html.Ul(
[
html.Li(
[
dcc.Link(
"Total Confirmed Cases",
href="/data/live-total-cases-growth",
)
]
),
html.Li(
[
dcc.Link(
"Day wise Confirmed Cases",
href="/data/live-cases-per-day",
)
]
),
],
className="submenu",
),
]
),
html.Li([html.A("Prediction", href="/data/prediction")]),
html.Li([html.A("About Corona", href="/about-corona")]),
html.Li([html.A("Contributors", href="/data/credits")]),
]
)
],
style={"textAlign": "center"},
className="row dropdownmenu gs-header",
),
# Included sniper as per suggestion
html.Div(dash_table.DataTable(), style={"display": "none"}),
html.Div(id="page-content"),
html.P(
[
u"\u00A9"
" Copyright 2020, Trackcorona.online | Data Sources: WHO and JHU and MOHFW(India)"
],
style={"textAlign": "center"},
className="twelve columns",
),
html.Div(
[
html.Div(
id="live-update-text",
style={"font-size": "10px", "textAlign": "center"},
),
dcc.Interval(
id="interval-component",
interval=20000 * 1000, # in milliseconds
n_intervals=0,
),
],
className="twelve columns",
),
]
)
now = dt.datetime.now()
formated_date = now.strftime("%d/%m/%Y, %H:%M:%S")
@app.callback(
Output("live-update-text", "children"), [Input("interval-component", "n_intervals")]
)
def update_date(n):
return [html.P("Last updated " + str(formated_date))]
@app.callback(Output("page-content", "children"), [Input("url", "pathname")])
def display_page(pathname):
if pathname == "/":
return home.layout
elif pathname == "/data/live-corona-world-map":
return livecoronamap.layout
elif pathname == "/data/live-corona-world-table":
return livecoronatable.layout
elif pathname == "/data/india-helpline":
return indiahelpline.layout
elif pathname == "/data/live-corona-usa-map":
return liveusamap.layout
elif pathname == "/data/live-corona-usa-table":
return liveusatable.layout
elif pathname == "/data/live-india-table":
return indiatable.layout
elif pathname == "/data/live-total-cases-growth":
return countrycasesgrowth.layout
elif pathname == "/data/live-cases-per-day":
return countryratechanges.layout
elif pathname == "/data/live-india-map":
return liveindiamap.layout
elif pathname == "/data/credits":
return credit.layout
elif pathname == "/data/prediction":
return prediction.layout
else:
return home.layout
@server.route("/")
def index():
return flask.redirect(flask.url_for("/data/"))
@server.route("/live-corona-world-table/")
def redirect_table():
return flask.redirect(flask.url_for("/data/"))
@server.route("/live-corona-world-map/")
def redirect_map():
return flask.redirect(flask.url_for("/data/"))
def sensor():
update()
print("Scheduler is alive!")
sched = BackgroundScheduler(daemon=True)
sched.add_job(sensor, "interval", minutes=120)
sched.start()
data_url = "/var/www/coronaApp/api/data.json"
@server.route("/api/all")
def api_index():
with open(data_url) as f:
d = json.load(f)
return d
@server.route("/api/confirmed")
def confirmed():
with open(data_url) as f:
d = json.load(f)
return d["confirmed"]
@server.route("/api/deaths")
def deaths():
with open(data_url) as f:
d = json.load(f)
return d["deaths"]
@server.route("/api/recovered")
def recovered():
with open(data_url) as f:
d = json.load(f)
return d["recovered"]
@server.route("/api/latest")
def latest():
with open(data_url) as f:
d = json.load(f)
return d["latest"]
@server.route("/prediction")
def prediction_html():
return flask.render_template('prediction.html')
@server.route("/sitemap.xml")
def sitemap():
template = flask.render_template('sitemap.xml')
response = flask.make_response(template)
response.headers['Content-Type'] = 'application/xml'
return response
@server.route("/about-corona")
def about_html():
url_world = "https://docs.google.com/spreadsheets/u/0/d/e/2PACX-1vR30F8lYP3jG7YOq8es0PBpJIE5yvRVZffOyaqC0GgMBN6yt0Q-NI8pxS7hd1F9dYXnowSC6zpZmW9D/pubhtml/sheet?headers=false&gid=0"
world_endrow = 2
df_total = worlddata.return_world_total_df(url_world, world_endrow)
df_total["Confirmed"] = df_total["Confirmed"].astype(int)
df_total["Deaths"] = df_total["Deaths"].astype(int)
df_total["Serious & Critical"] = df_total["Serious & Critical"].astype(int)
df_total["Recovered"] = df_total["Recovered"].astype(int)
confirmed = df_total["Confirmed"].values[0]
deaths = df_total["Deaths"].values[0]
serious = df_total["Serious & Critical"].values[0]
recovered = df_total["Recovered"].values[0]
world_confirmed = ("{:,}".format(confirmed))
world_deaths = ("{:,}".format(deaths))
world_serious = ("{:,}".format(serious))
world_recovered = ("{:,}".format(recovered))
return flask.render_template('aboutcorona.html', world_confirm=world_confirmed, world_death=world_deaths, world_serious=world_serious, world_recovered=world_recovered)
@server.route("/india-table")
def india_html():
india_url = "https://www.mohfw.gov.in/"
india_pos = 0
india_strip = 3
india_endrow = 3
df_india_table = indiadata.return_india_table_df(india_url, india_pos, india_strip)
df_india_total = indiadata.return_india_total_df(india_url, india_pos, india_endrow)
df_india_total["Confirmed"] = df_india_total["Confirmed"].astype(int)
df_india_total["Deaths"] = df_india_total["Deaths"].astype(int)
df_india_total["Recovered"] = df_india_total["Recovered"].astype(int)
india_confirmed = df_india_total["Confirmed"].values[0]
india_deaths = df_india_total["Deaths"].values[0]
india_recovered = df_india_total["Recovered"].values[0]
india_confirmed = ("{:,}".format(india_confirmed))
india_deaths = ("{:,}".format(india_deaths))
india_recovered = ("{:,}".format(india_recovered))
return flask.render_template('indiatable.html', tables=[df_india_table.to_html(classes='ui celled table', table_id='india-table')], titles=df_india_table.columns.values, india_confirm=india_confirmed, india_death=india_deaths, india_recovered=india_recovered)
if __name__ == "__main__":
app.run_server(debug=True)