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
Alexander Huddleston 527723d605 Initial commit.
2020-03-25 08:12:59 -05:00

31 lines
1.2 KiB
Python

#!/usr/bin/python
import requests
from bs4 import BeautifulSoup
def get_current_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)
table = parsed_html.find('table', id='main_table_countries_today')
all_rows = table.findAll('tr')
for row in all_rows:
if(row and row.findAll('td') and row.find('a')):
all_cols = row.findAll('td')
if(row.find('a').text == 'USA'):
return f'''
{row.find('a').text}
Total Cases: {all_cols[1].text}
New Cases: {all_cols[2].text}
Total Deaths: {all_cols[3].text}
New Deaths: {all_cols[4].text}
Total Recovered: {all_cols[5].text}
Active Cases: {all_cols[6].text}
Serious/Critical: {all_cols[7].text}
Total Cases/1M Population: {all_cols[8].text}
'''
if(__name__ == '__main__'):
print(get_current_data())