from pandas import read_csv import pandas as pd import requests import os import discord 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(): series = read_csv(get_csv(), header=0, parse_dates=[0], index_col=0, squeeze=True) california = series.loc[series['Province_State'] == 'California'].sum() confirmed = california['Confirmed'] deaths = california['Deaths'] recovered = california['Recovered'] embed = discord.Embed(description='Most recent Corona stats for California', 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