Package: corona-api
corona-apiAn asynchronous wrapper for theNovelCOVID APIwritten in Python.This is designed for bots usingdiscord.pybut there is no discord-specific code so you are free to use this in any project as required.RequirementsPython 3.5 or aboveaiohttp (python3 -m pip install -U aiohttp)InstallationUsing pip (recommended)python3 -m pip install -U corona_apiSupportGet support for this on Discord, either on ourofficial serveror theNovelCOVID server.Optional parameters in methodsParameterSupported methodsAccepted valuesyesterday-all()-get_country_data()-get_country_list()-get_all_countries()-get_all_states()-get_single_state()-get_state_list()-get_all_continents()-get_single_continent()-True-Falsetwo_days_ago-all()-get_country_data()-get_country_list()-get_all_countries()-get_single_continent()-get_all_continents()-True-Falsesort-get_all_countries()-get_all_states()-get_all_continents()-'cases'-'deaths'-'recovered'-'active'-'tests'-'critical'-'deathsPerOneMillion'-'testsPerOneMillion'-'todayCases'-'todayDeaths'-'casesPerOneMillion'-'active'allow_none-all()-get_country_data()-get_country_list()-get_all_countries()-get_all_continents()-get_single_continent()-get_single_state()-get_state_list()-get_all_states()-gov_country()-True-FalseExamplesThe following examples cover the basic usage of the library and its various features.
Note; many methods also supportyesterday=True,sort='sort method'andallow_none=Truekwargs to get data from the previous day or sorted by various parameters. Refer to the table above to find out which ones do and do not.Discord botThere is an example cog for your Discord bothere.Basic dataGlobal dataimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_all():data=awaitclient.all()#get global dataprint(data.cases,data.deaths)#print the number of global cases and deathsawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_all())Data for a specific countryimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_country():data=awaitclient.get_country_data('UK')#get data for the UK today,print(data.cases,data.deaths)#print the number of cases and deaths for the UKawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_country())Data for more than one countryimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_countries():data=awaitclient.get_country_list('UK','USA','China')#get data for specified countries#to get data for every country supported, use:  get_all_countries()print(data)#prints a list of CountryStatisticsawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_countries())US StatesData for a specific stateimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_state():data=awaitclient.get_single_state('Ohio')#get data for Ohio today,print(data.cases,data.deaths)#print the number of cases and deaths for Ohioawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_state())Data for more than one stateimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_states():data=awaitclient.get_state_list('Ohio','California','Texas')#get data for specified states#to get data for every state supported, use:  get_all_states()print(data)#prints a list of StateStatisticsawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_states())Historical statisticsHistorical data globallyimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_history():data=awaitclient.get_country_history('all','all')#get all the historical data for the worldprint(data.name,data.case_history[0].date,data.case_history[0].value)#print name (in this case 'Global'), the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_history())Historical data for a countryimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_history():data=awaitclient.get_country_history('UK',7)#get the past week of historical data for the UKprint(data.name,data.case_history[0].date,data.case_history[0].value)#print name, the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_history())Historical data for a provinceimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_history_province():data=awaitclient.get_province_history('UK','Gibraltar',7)#get the past week of historical data for Gibraltar, UKprint(data.province,data.case_history[0].date,data.case_history[0].value)#print province name, the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_history_province())Historical data for a county within a US stateimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_county():data=awaitclient.get_state_county_history('Ohio','Adams')#get all historical data for Adams, Ohio, USAprint(data.name,data.province,data.case_history[0].date,data.case_history[0].value)#print state and county name, the date of the first entry, and the number of cases for that dateawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_county())John Hopkins CSSEAll data from the JHU CSSEimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_jhu():data=awaitclient.get_jhu_csse_data()#get data for every province and country JHU supportsprint(data)#print a long list of JhuCsseStatisticsawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_jhu())Data for a county within a US stateimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_jhu_county():data=awaitclient.get_jhu_county_data('Ohio','Adams')#get data for Adams, Ohioprint(data.province_name,data.county_name,data.confirmed_cases)#print the state, county and case numberawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_jhu_county())Data for every county in the USAimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_jhu_counties():data=awaitclient.get_jhu_all_counties()print(data)#print a long list of JhuCsseStatisticsawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_jhu_counties())Continental dataData for every continentimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_conts():data=awaitclient.get_all_continents()first=data[0]print(first.name,first.cases,first.deaths)#print some info for the first continent in the listawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_conts())Data for a single continentimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_one_cont():data=awaitclient.get_single_continent('Europe')print(data.name,data.cases,data.deaths)#print some info for the specified continentawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_one_cont())New York TimesUSA data from NY Timesimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_nyt_us():data=awaitclient.get_nyt_usa_data()first=data[0]print(first.date,first.cases,first.deaths)#print first piece of dataawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_nyt_us())All USA state data from NY Timesimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_nyt_states():data=awaitclient.get_nyt_all_states()first=data[0]print(first.state,first.date,first.cases)#print some data from the frst elementawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_nyt_states())Data for a single state from NY Timesimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_nyt_state():data=awaitclient.get_nyt_single_state('Ohio')first=date[0]print(first.date,first.cases,first.deaths)#print the first date, and case/death numberawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_nyt_state())Every county from NY Timesimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_counts():data=awaitclient.get_nyt_all_counties()first=data[0]print(first.date,first.cases,first.deaths)#print part of the first piece of dataawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_counts())Counties from NYT filtered by nameimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_one_county():data=awaitclient.get_nyt_single_county('Adams')first=data[0]print(first.date,first.cases,first.deaths)#print part of the first piece of dataawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_one_county())Apple MobilityEvery country supported by Apple Mobility Dataimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefall_apples():data=awaitclient.apple_all_countries()print(data)#print all supported countriesawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(apples())Every subregion within a country for Apple Mobilityimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_subregions():data=awaitclient.apple_subregions('UK')print(data.subregions)#print all supported subregions within the countryawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_subregions())Apple's Mobility data for a subregionimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_one_sub():data=awaitclient.apple_mobility_data('UK','London')first=data.statistics[0]print(first.date,first.name,first.driving)#print some data about the first resultawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_one_sub())Governmental dataAll countries supported by the API for government dataimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_gov_countries():data=awaitclient.gov_all_countries()print(data)#print the supported countriesawaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_gov_countries())Get the data from a country's governmental dataimportcorona_apiimportasyncioclient=corona_api.Client()asyncdefget_country_gov():data=awaitclient.gov_country('UK')print(data)#probably will return a large amount of dict data.awaitclient.request_client.close()#close the ClientSessionasyncio.get_event_loop().run_until_complete(get_country_gov())NoteDue to the fact that each country's governmental/official statistics website is different, it is not feasible to create a standardised class for the data. However, if you interpret the data received from the API, it should be relatively simple to work with the given information.