Skip to content

Commit 08ce4b5

Browse files
authored
Create Covid19_Info.py (#17)
1 parent d93228f commit 08ce4b5

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Covid19_Info.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import bs4
2+
import requests
3+
4+
try:
5+
print('For which region you want to see the COVID-19 cases?\nPlease write below!\n'
6+
'Example:\noverall/total/worldwide/all - for overall cases in the world\ncountry/COunTRY/COUNTRY/Country '
7+
'- for any specific country')
8+
c_query = input().lower()
9+
print('\n')
10+
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:
11+
def world_cases():
12+
13+
url = 'https://www.worldometers.info/coronavirus/'
14+
info_html = requests.get(url)
15+
info = bs4.BeautifulSoup(info_html.text, 'lxml')
16+
info2 = info.find('div', class_='content-inner')
17+
new_info = info2.findAll('div', id='maincounter-wrap')
18+
print('Worldwide Covid-19 information--')
19+
20+
for i in new_info:
21+
head = i.find('h1', class_=None).get_text()
22+
counting = i.find('span', class_=None).get_text()
23+
print(head, "", counting)
24+
25+
world_cases()
26+
27+
elif 'country' in c_query or 'specific country' in c_query:
28+
def country_cases():
29+
30+
print('Write the country name?')
31+
c_name = input().lower()
32+
print('\n')
33+
c_url = f'https://www.worldometers.info/coronavirus/country/{c_name}/'
34+
data_html = requests.get(c_url)
35+
c_data = bs4.BeautifulSoup(data_html.text, 'lxml')
36+
new_data = c_data.find('div', class_='content-inner').findAll('div', id='maincounter-wrap')
37+
print(f'Covid-19 information for {c_name.capitalize()}--')
38+
39+
for j in new_data:
40+
c_head = j.find('h1', class_=None).get_text()
41+
c_counting = j.find('span', class_=None).get_text()
42+
print(c_head, "", c_counting)
43+
44+
country_cases()
45+
46+
except Exception as e:
47+
print('There is something wrong! Please try again.')

0 commit comments

Comments
 (0)