-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathCases_Info_Covid.py
47 lines (38 loc) · 1.99 KB
/
Cases_Info_Covid.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
import bs4
import requests
try:
print('For which region you want to see the COVID-19 cases?\nPlease write below!\n'
'Example:\noverall/total/worldwide/all - for overall cases in the world\ncountry/COunTRY/COUNTRY/Country '
'- for any specific country')
c_query = input().lower()
print('\n')
if 'overall' in c_query or 'over all' in c_query or 'world' in c_query or 'total' in c_query or 'worldwide' in c_query or 'all' in c_query:
def world_cases():
url = 'https://www.worldometers.info/coronavirus/'
info_html = requests.get(url)
info = bs4.BeautifulSoup(info_html.text, 'lxml')
info2 = info.find('div', class_='content-inner')
new_info = info2.findAll('div', id='maincounter-wrap')
print('Worldwide Covid-19 information--')
for i in new_info:
head = i.find('h1', class_=None).get_text()
counting = i.find('span', class_=None).get_text()
print(head, "", counting)
world_cases()
elif 'country' in c_query or 'specific country' in c_query:
def country_cases():
print('Write the country name?')
c_name = input().lower()
print('\n')
c_url = f'https://www.worldometers.info/coronavirus/country/{c_name}/'
data_html = requests.get(c_url)
c_data = bs4.BeautifulSoup(data_html.text, 'lxml')
new_data = c_data.find('div', class_='content-inner').findAll('div', id='maincounter-wrap')
print(f'Covid-19 information for {c_name.capitalize()}--')
for j in new_data:
c_head = j.find('h1', class_=None).get_text()
c_counting = j.find('span', class_=None).get_text()
print(c_head, "", c_counting)
country_cases()
except Exception as e:
print('There is something wrong! Please try again.')