Fixing corona herror handling
This commit is contained in:
parent
1944a168c2
commit
c221810e68
@ -14,7 +14,6 @@ def get_csv():
|
||||
|
||||
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)
|
||||
|
||||
@ -23,12 +22,18 @@ def get_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()
|
||||
last_updated = series['Last_Update'].iloc[0]
|
||||
state_query = series.loc[series['Province_State'] == state]
|
||||
if state_query.empty:
|
||||
embed = discord.Embed(description="No results found for %s.\n\nPlease enter a valid US state" % state, color=0x428bca, type="rich")
|
||||
embed.set_author(name="CSSE at Johns Hopkins University", icon_url='https://avatars2.githubusercontent.com/u/60674295')
|
||||
return embed
|
||||
sums = state_query.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 = discord.Embed(description="Most recent Corona stats for %s\nUpdated once a day\n(Last update was %s)" % (state, last_updated), 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)
|
||||
@ -38,7 +43,9 @@ def sum_numbers(state):
|
||||
|
||||
def parse_message(message):
|
||||
try:
|
||||
state = string.capwords(' '.join(message.split()[1:]))
|
||||
state = string.capwords(' '.join(message.lstrip('!corona').split()))
|
||||
if not state:
|
||||
state = 'California'
|
||||
except IndexError:
|
||||
state = 'California'
|
||||
return sum_numbers(state)
|
||||
|
@ -33,6 +33,10 @@ def get_help_message(method):
|
||||
'Admin use only. Deletes dragon bot\'s messages from the channel',
|
||||
'Usage: !cleanup'
|
||||
],
|
||||
'corona': [
|
||||
'Pulls the latest corona virus stats per state from Johns Hopkins data',
|
||||
'Usage: !corona <some US state>\neg: !corona Colorado'
|
||||
],
|
||||
'decide': [
|
||||
'Dragon-bot will help make the tough decisions for you',
|
||||
' If there is only one option, it will give you a yes or no',
|
||||
@ -162,7 +166,7 @@ def get_help_message(method):
|
||||
def get_help_embed(client):
|
||||
categories = {
|
||||
'fun': ['clap', 'redanda', 'birb', 'youtube', 'dog', 'excuse', 'greentext', 'lewd', 'message', 'meme', 'homepage', 'pout', 'roll', 'smug', 'quake', 'wink',],
|
||||
'util': ['8ball', 'decide', 'info', 'icon', 'wallpaper', 'weather', 'stock', 'tts', 'issue'],
|
||||
'util': ['corona', '8ball', 'decide', 'info', 'icon', 'wallpaper', 'weather', 'stock', 'tts', 'issue'],
|
||||
'users': ['help', 'invite', 'purge', 'roles', 'source', 'minecraft'],
|
||||
'admin': ['emoji', 'cleanup']
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user