33 lines
1.2 KiB
Python
33 lines
1.2 KiB
Python
#!/usr/bin/python
|
|
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
from covidData import covidData
|
|
|
|
# temporary database
|
|
covid_db = {}
|
|
|
|
|
|
def update_data():
|
|
data_html = requests.get('https://www.worldometers.info/coronavirus/')
|
|
if(data_html.status_code == '200' or data_html.status_code == 200):
|
|
parsed_html = BeautifulSoup(data_html.text, features='html.parser')
|
|
table = parsed_html.find('table', id='main_table_countries_today')
|
|
for row in table.findAll('tr'):
|
|
if(row and row.findAll('td')):
|
|
if(row.find('a')):
|
|
covid_db[row.find('a').text.upper()] = covidData(
|
|
row.find('a').text, [r.text for r in row.findAll('td')])
|
|
elif(row.findAll('td')[0] and row.findAll('td')[0].text):
|
|
covid_db[row.findAll('td')[0].text.replace(':', '').upper()] = covidData(
|
|
row.findAll('td')[0].text.replace(':', ''), [r.text for r in row.findAll('td')])
|
|
|
|
|
|
def get_covid_data(selection):
|
|
if(not covid_db):
|
|
update_data()
|
|
return covid_db[selection].get_formatted_data()
|
|
|
|
|
|
if(__name__ == '__main__'):
|
|
print(get_covid_data())
|