async def _get_country(): client = cor.Client() obj = await client.get_all_countries() await client.request_client.session.close() return obj
import corona_api as cor import asyncio import pandas as pd import numpy as np #$$ client = cor.Client() data_list = await (client.get_all_countries()) await client.request_client.session.close() df = pd.DataFrame([(i.__dict__) for i in data_list]) df['iso3'] = pd.DataFrame([i.info.iso3 for i in data_list]) df2 = pd.read_csv('~/personal_projects/corona_virus/data/all_countries_by_continent.csv') df2.columns = df2.columns = [i.lower() for i in df2.columns.values] df = pd.merge(df, df2, left_on='iso3', right_on='iso-alpha3 code', how='outer') country_is_null_in_df2 = df[pd.isnull(df['country or area'])]['name'] country_is_null_in_df = df[pd.isnull(df['name'])]['country or area'] df = df.dropna(how='any', subset= ['name', 'country or area'])
def __init__(self, bot): self.session = aiohttp.ClientSession() self.bot = bot self.corona = corona_api.Client()
def __init__(self, bot): self.bot = bot self.corona = corona_api.Client()
async def covid(ctx, *, country='default'): corona = corona_api.Client() if country == 'default': data = await corona.all() # get global data embed = discord.Embed(title='COVID-19 Stats', description='**Worldwide Stats:**', color=bot.color_code, timestamp=ctx.message.created_at) embed.add_field(name='**Global Cases**', value=f'{data.cases}', inline=False) embed.add_field(name='**Global Deaths**', value=f'{data.deaths}', inline=False) embed.add_field(name='**Global Recoveries**', value=f'{data.recoveries}', inline=False) embed.add_field(name='**Active Cases**', value=f'{data.active}', inline=False) embed.add_field(name='**Cases Today**', value=f'{data.today_cases}', inline=False) embed.add_field(name='**Deaths Today**', value=f'{data.today_deaths}', inline=False) embed.set_footer( text=f'© {bot.user.name} | Owned by {ctx.guild.owner}', icon_url=bot.user.avatar_url) await ctx.send(embed=embed) await corona.request_client.close() # close the ClientSession else: try: data = await corona.get_country_data(country) except: embed = discord.Embed(title=f'COVID-19 Stats', description=f'**Country Not Found!**', color=bot.color_code, timestamp=ctx.message.created_at) embed.set_footer( text=f'© {bot.user.name} | Owned by {ctx.guild.owner}', icon_url=bot.user.avatar_url) await corona.request_client.close() await ctx.send(embed=embed) return embed = discord.Embed( title=f'COVID-19 Stats', description=f'**{country.title()}\'s COVID-19 Stats:**', color=bot.color_code, timestamp=ctx.message.created_at) embed.add_field(name='**Total Cases**', value=f'{data.cases}', inline=False) embed.add_field(name='**Total Deaths**', value=f'{data.deaths}', inline=False) embed.add_field(name='**Total Recoveries**', value=f'{data.recoveries}', inline=False) embed.add_field(name='**Active Cases**', value=f'{data.active}', inline=False) embed.add_field(name='**Cases Today**', value=f'{data.today_cases}', inline=False) embed.add_field(name='**Deaths Today**', value=f'{data.today_deaths}', inline=False) embed.set_footer( text=f'© {bot.user.name} | Owned by {ctx.guild.owner}', icon_url=bot.user.avatar_url) await ctx.send(embed=embed) await corona.request_client.close() # close the ClientSession