-
Notifications
You must be signed in to change notification settings - Fork 0
/
Corona_Tracker.py
102 lines (99 loc) · 4.3 KB
/
Corona_Tracker.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
'''
Programmer - Sihab Sahariar
Website : https://sihabsahariar.github.io/
Corona Tracker is an opensource python library to get information of a particular country about Corona Virus.
Using webscrapping technology I implemented it to use in various project. There are 24 methods to get information.
The methods are listed here -
-updated
-country
-countryInfo
-cases
-todayCases
-deaths
-todayDeaths
-recovered
-todayRecovered
-active
-critical
-casesPerOneMillion
-deathsPerOneMillion
-tests
-testsPerOneMillion
-population
-continent
-oneCasePerPeople
-oneDeathPerPeople
-oneTestPerPeople
-undefined
-activePerOneMillion
-recoveredPerOneMillion
-criticalPerOneMillion
'''
from urllib.request import Request, urlopen
import json
class CoronaTracker:
def __init__(self,countryName):
self.loadedSuccessfully = False
self.data_json = None
if countryName == "":
return None
else:
self.countryName= countryName
def loadData(self):
try:
req = Request('https://corona.lmao.ninja/v2/countries/'+self.countryName, headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
self.data_json = json.loads(webpage)
self.loadedSuccessfully = True
except:
None
def errorMessage(self):
return ('Check Internet Connection and loadData function call')
def updated(self):
return self.data_json['updated'] if self.loadedSuccessfully ==True else self.errorMessage()
def country(self):
return self.data_json['country'] if self.loadedSuccessfully ==True else self.errorMessage()
def countryInfo (self):
return self.data_json['countryInfo'] if self.loadedSuccessfully ==True else self.errorMessage()
def cases (self):
return self.data_json['cases'] if self.loadedSuccessfully ==True else self.errorMessage()
def todayCases(self):
return self.data_json['todayCases'] if self.loadedSuccessfully ==True else self.errorMessage()
def deaths(self):
return self.data_json['deaths'] if self.loadedSuccessfully ==True else self.errorMessage()
def todayDeaths(self):
return self.data_json['todayDeaths'] if self.loadedSuccessfully ==True else self.errorMessage()
def recovered (self):
return self.data_json['recovered'] if self.loadedSuccessfully ==True else self.errorMessage()
def todayRecovered(self):
return self.data_json['todayRecovered'] if self.loadedSuccessfully ==True else self.errorMessage()
def active(self):
return self.data_json['active'] if self.loadedSuccessfully ==True else self.errorMessage()
def critical(self):
return self.data_json['critical'] if self.loadedSuccessfully ==True else self.errorMessage()
def casesPerOneMillion(self):
return self.data_json['casesPerOneMillion'] if self.loadedSuccessfully ==True else self.errorMessage()
def deathsPerOneMillion(self):
return self.data_json['deathsPerOneMillion'] if self.loadedSuccessfully ==True else self.errorMessage()
def tests(self):
return self.data_json['tests'] if self.loadedSuccessfully ==True else self.errorMessage()
def testsPerOneMillion(self):
return self.data_json['testsPerOneMillion'] if self.loadedSuccessfully ==True else self.errorMessage()
def population(self):
return self.data_json['population'] if self.loadedSuccessfully ==True else self.errorMessage()
def continent(self):
return self.data_json['continent'] if self.loadedSuccessfully ==True else self.errorMessage()
def oneCasePerPeople(self):
return self.data_json['oneCasePerPeople'] if self.loadedSuccessfully ==True else self.errorMessage()
def oneDeathPerPeople(self):
return self.data_json['oneDeathPerPeople'] if self.loadedSuccessfully ==True else self.errorMessage()
def oneTestPerPeople (self):
return self.data_json['oneTestPerPeople'] if self.loadedSuccessfully ==True else self.errorMessage()
def undefined(self):
return self.data_json['undefined'] if self.loadedSuccessfully ==True else self.errorMessage()
def activePerOneMillion(self):
return self.data_json['activePerOneMillion'] if self.loadedSuccessfully ==True else self.errorMessage()
def recoveredPerOneMillion(self):
return self.data_json['recoveredPerOneMillion'] if self.loadedSuccessfully ==True else self.errorMessage()
def criticalPerOneMillion(self):
return self.data_json['criticalPerOneMillion'] if self.loadedSuccessfully ==True else self.errorMessage()