From 76b0118cb22084d99eda97988ef1d7706389191e Mon Sep 17 00:00:00 2001 From: Luke Robles Date: Sun, 24 Jan 2021 19:38:53 -0800 Subject: [PATCH] Adding vaccination numbers --- app/corona.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/app/corona.py b/app/corona.py index cca8d923..4f75a57e 100644 --- a/app/corona.py +++ b/app/corona.py @@ -1,8 +1,10 @@ +from bs4 import BeautifulSoup from pandas import read_csv +from urllib.parse import urlparse +import discord +import os import pandas as pd import requests -import os -import discord import string def get_csv(): @@ -59,10 +61,28 @@ def sum_numbers(location): embed.add_field(name=':rotating_light: Confirmed Cases :rotating_light:', value=confirmed, inline=False) embed.add_field(name=':hospital: Recovered Cases :hospital:', value=recovered, inline=False) embed.add_field(name=':skull_crossbones: Deaths :skull_crossbones:', value=deaths, inline=False) - embed.add_field(name='Source', value='https://github.com/CSSEGISandData/COVID-19') + embed.add_field(name=':sparkles: :syringe: NEW!: Percent vaccinated :syringe: :sparkles:', value=get_vaccination_data(location), inline=False) + embed.add_field(name='Source', value="https://github.com/CSSEGISandData/COVID-19\nVaccination numbers pulled from\nhttps://covidvaxcount.live") return embed +def get_vaccination_data(location): + url = requests.get('https://covidvaxcount.live') + soup = BeautifulSoup(url.content, features="html.parser") + + data = [] + table = soup.find("div", {"class": 'table-responsive'}) + table_body = table.find('tbody') + + rows = table_body.find_all('tr') + for row in rows: + cols = row.find_all('td') + cols = [ele.text.strip() for ele in cols] + data.append([ele for ele in cols if ele]) # Get rid of empty values + + state_name, num_vaccinated, population, percent_vaccinated = list(filter(lambda x: x[0] == location, data))[0] + return percent_vaccinated + def parse_message(message): try: state = string.capwords(' '.join(message.lstrip('!corona').split()))