From e8aec76c0441aa2a0fbce20fb48cc617dfb953fb Mon Sep 17 00:00:00 2001 From: Umesh Singh <83420185+Umesh-01@users.noreply.github.com> Date: Sat, 1 Oct 2022 21:43:49 +0530 Subject: [PATCH] CoVID19 cases using python --- .../Covid19_Info.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Amazing Python Projects_Scripts/Covid19_Info.py diff --git a/Amazing Python Projects_Scripts/Covid19_Info.py b/Amazing Python Projects_Scripts/Covid19_Info.py new file mode 100644 index 000000000..06eaeca84 --- /dev/null +++ b/Amazing Python Projects_Scripts/Covid19_Info.py @@ -0,0 +1,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.')