This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
covid-19-discord-bot/parse_data.py

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())