-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
42 lines (35 loc) · 979 Bytes
/
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
from flask import Flask,render_template
import pygal
import json
import requests
app=Flask(__name__)
def refresh():
url='https://covid.ourworldindata.org/data/owid-covid-data.json'
a=requests.get(url)
c=a.json()
countries=[]
for i in c.keys():
countries.append(i)
data={}
for i in countries:
try:
cases=c[i]['data'][-1]['total_cases']
j=i.lower()[:2]
if j in data:
data[j]=cases
else:
data[j]=cases
except KeyError:
continue
date=c[i]['data'][-1]['date']
a=pygal.maps.world.World()
a.add('Case',data)
a.title="COVID-19 Cases Up to the date "+date
a.value_formatter = lambda y: "{:,}".format(y)
a=a.render_data_uri()
return a
@app.route('/')
def line_route():
return render_template('charts.html',chart=refresh())
if __name__=='__main__':
app.run()