-
Notifications
You must be signed in to change notification settings - Fork 2
/
casedata.py
61 lines (46 loc) · 1.36 KB
/
casedata.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
import requests
import plotly.graph_objects as go
import plotly.io as pio
india=requests.get('https://api.covid19india.org/data.json')
globaldata=requests.get('https://corona.lmao.ninja/v2/all?yesterday=true')
current_data=india.json()
globaldatas=globaldata.json()
alldata=current_data["statewise"][0]
#list
def getCasesTimeSeries(d):
date = []
totalconfirmed = []
totaldeceased = []
totalrecovered = []
for i in d['cases_time_series']:
date.append(i.get('date'))
totalconfirmed.append(i.get('totalconfirmed'))
totaldeceased.append(i.get('totaldeceased'))
totalrecovered.append(i.get('totalrecovered'))
return date,totalconfirmed,totaldeceased,totalrecovered
alllist=getCasesTimeSeries(current_data)
#date=current_data["date"]
# dat =]
#for i in range(0,len(current_data)):
# dat = dat.append(current_data[i]["date"])
#print(dat)
# 1 2 3 45 6
#graph generation
fig = go.Figure()
fig.add_trace(go.Scatter(
x=alllist[0],
y=alllist[1],
name = '<b>Total Cases</b>', # Style name/legend entry with html tags
connectgaps=True # override default to connect the gaps
))
fig.add_trace(go.Scatter(
x=alllist[0],
y=alllist[2],
name='Total deaths',
))
fig.add_trace(go.Scatter(
x=alllist[0],
y=alllist[3],
name='Recovered',
))
pio.write_html(fig, file='templates/graph.html', auto_open=False)