45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from pandas import read_csv
|
|
import pandas as pd
|
|
import requests
|
|
import os
|
|
import discord
|
|
import string
|
|
|
|
def get_csv():
|
|
git_url = 'https://api.github.com/repos/CSSEGISandData/COVID-19/contents/csse_covid_19_data/csse_covid_19_daily_reports'
|
|
git_blob = requests.get(git_url).json()[-2]
|
|
file_name = git_blob['name']
|
|
download_url = git_blob['download_url']
|
|
local_csv = "/app/%s" % file_name
|
|
|
|
if not os.path.exists(local_csv):
|
|
print("no local csv found, downloading latest")
|
|
# url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/%s.csv" % date
|
|
r = requests.get(download_url, allow_redirects=True)
|
|
open(local_csv, 'wb').write(r.content)
|
|
|
|
return local_csv
|
|
|
|
|
|
def sum_numbers(state):
|
|
series = read_csv(get_csv(), header=0, parse_dates=[0], index_col=0, squeeze=True)
|
|
sums = series.loc[series['Province_State'] == state].sum()
|
|
confirmed = sums['Confirmed']
|
|
deaths = sums['Deaths']
|
|
recovered = sums['Recovered']
|
|
|
|
embed = discord.Embed(description="Most recent Corona stats for %s" % state, color=0x428bca, type="rich")
|
|
embed.set_author(name="CSSE at Johns Hopkins University", icon_url='https://avatars2.githubusercontent.com/u/60674295')
|
|
embed.add_field(name='Confirmed Cases', value=confirmed)
|
|
embed.add_field(name='Recovered Cases', value=recovered)
|
|
embed.add_field(name='Deaths', value=deaths)
|
|
embed.add_field(name='Source', value='https://github.com/CSSEGISandData/COVID-19')
|
|
return embed
|
|
|
|
def parse_message(message):
|
|
try:
|
|
state = string.capwords(' '.join(message.split()[1:]))
|
|
except IndexError:
|
|
state = 'California'
|
|
return sum_numbers(state)
|