-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcasesDataSet.py
32 lines (22 loc) · 1.04 KB
/
casesDataSet.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
import requests, json
import traceback
from binary_search import binary_search
def numberOfCasesInCountry(Country):
url_summary = "https://api.covid19api.com/summary"
payload = {}
headers = {}
response = requests.request("GET", url_summary, headers=headers, data=payload)
json_data_summary = response.json()
cindex = binary_search(json_data_summary['Countries'], Country, 'Country')
try:
return changeJson('TotalConfirmed', json_data_summary, cindex), \
changeJson('TotalDeaths', json_data_summary, cindex), \
changeJson('TotalRecovered', json_data_summary, cindex), \
changeJson('NewConfirmed', json_data_summary, cindex), \
changeJson('NewRecovered', json_data_summary, cindex), \
changeJson('NewDeaths', json_data_summary, cindex)
except TypeError:
traceback.print_exc()
return 'blhjk'
def changeJson(parameter, json_data_summary, cindex):
return "{:,}".format(json_data_summary['Countries'][cindex][parameter])