forked from 3b1b/manim
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathByregion.py
More file actions
47 lines (42 loc) · 1.88 KB
/
Byregion.py
File metadata and controls
47 lines (42 loc) · 1.88 KB
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
import requests
import json
import pandas as pd
from json2xml import json2xml
class SWEDGovCoronaAPI:
def __init__(self):
self.OCasecountsDaily='https://api.apify.com/v2/key-value-stores/8mRFdwyukavRNCr42/records/LATEST?disableRedirect=true'
self.OCasecountsAll='https://api.apify.com/v2/datasets/Nq3XwHX262iDwsFJS/items?format=json&clean=1'
AllApi=SWEDGovCoronaAPI()
class SWEDCovid19:
def ByregionCountDaily(oparam='JSON'):
TotalCaseCount=requests.get(AllApi.OCasecountsDaily)
TotalCaseCount=json.loads(TotalCaseCount.content)
if oparam=='JSON':
#for region in TotalCaseCount["infectedByRegion"]:
# alist=(region['region'],region['infectedCount'],region['deathCount'],region['intensiveCareCount'])
# print(alist)
return TotalCaseCount["infectedByRegion"]
elif oparam=='DF':
return pd.DataFrame(TotalCaseCount['infectedByRegion'])
else:
return 'Param missing'
def ByregionCountAll(oparam='JSON'):
TotalCaseCount=requests.get(AllApi.OCasecountsAll)
TotalCaseCount=json.loads(TotalCaseCount.content)
store_list = []
for item in TotalCaseCount:
store_list.append(item)
if oparam=='JSON':
#for region in TotalCaseCount["infectedByRegion"]:
# alist=(region['region'],region['infectedCount'],region['deathCount'],region['intensiveCareCount'])
#print(item["infectedByRegion"])
#print(store_list[6])
return store_list
elif oparam=='DF':
return pd.DataFrame(store_list)
else:
return 'Param missing'
#print (SWEDCovid19.ByregionCountDaily('JSON'))
#print (SWEDCovid19.ByregionCountDaily('DF'))
#print (SWEDCovid19.ByregionCountAll('JSON'))
#print (SWEDCovid19.ByregionCountAll('DF'))