forked from rayansudeora/AntyVyrus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scraper.py
75 lines (48 loc) · 1.39 KB
/
scraper.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
import requests
import json
import website
API_KEY = "tDEHxW_Jr1TW"
PROJECT_TOKEN = "tENR1ercxLe_"
RUN_TOKEN = "tU7b3K0S4pyz"
def main(text):
class Data:
def __init__(self, api_key, project_token):
self.API_Key = api_key
self.Project_Token = project_token
self.params = {
"api_key": self.API_Key
}
self.data = self.get_data()
def get_data(self):
response = requests.get(f'https://www.parsehub.com/api/v2/projects/{self.Project_Token}/last_ready_run/data', params=self.params)
data = json.loads(response.text)
return data
def get_country_info(self, country):
data = self.data["country"]
for content in data:
if content['name'].lower() == country.lower():
return content
return "0"
def get_list(self):
countries = []
for country in self.data['country']:
countries.append(country['name'].lower())
return countries
data = Data(API_KEY, PROJECT_TOKEN)
def return_data(country):
try:
country_stuff = data.get_country_info(country)
country_stuff = data.get_country_info(country)
cases = (country_stuff['total_cases'])
deaths = (country_stuff['total_deaths'])
return cases, deaths
except KeyError:
deaths = 0
return cases,deaths
data = Data(API_KEY, PROJECT_TOKEN)
#print(data.get_data())
user_country = text
cases_deaths = return_data(user_country)
return cases_deaths
if __name__ == "__main__":
main()