Skip to content

Commit

Permalink
support for new endpoints and parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
apex2504 committed Apr 5, 2020
1 parent 3064caf commit 59c9305
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 22 deletions.
4 changes: 2 additions & 2 deletions corona_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from .statistics import *
from .utils import *

__version__ = "0.6.2"
__author__ = "apex2504"
__version__ = "0.6.4"
__author__ = "Rob Wainwright // apex2504"
__license__ = "MIT"
24 changes: 8 additions & 16 deletions corona_api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,6 @@ async def get_all_countries(self):
list_of_countries.append(self._compile_country_data(c))

return list_of_countries


async def _request_all_states(self):
"""
Request the stats for all US states
"""
endpoint = STATES.format(self.api_url)
return await self.request_client.make_request(endpoint)


def _compile_state(self, state_dict):
Expand All @@ -165,7 +157,8 @@ async def get_all_states(self):
"""
Get the stats for all US states
"""
state_info = await self._request_all_states()
endpoint = ALL_STATES.format(self.api_url)
state_info = await self.request_client.make_request(endpoint)

state_data = []

Expand All @@ -180,9 +173,8 @@ async def get_single_state(self, state):
"""
Get the stats for a specific province of a country
"""
all_states = await self._request_all_states()

state_info = next(s for s in all_states if s["state"].lower() == state.lower())
endpoint = SINGLE_STATE.format(self.api_url, state)
state_info = await self.request_client.make_request(endpoint)

compiled_state = self._compile_state(state_info)

Expand Down Expand Up @@ -217,22 +209,22 @@ def _generate_history(self, historical_stats):
)


async def get_country_history(self, country="all"):
async def get_country_history(self, country="all", last_days='all'):
"""
Get historical data for a specific country or globally.
Defaults to 'all' in order to get global data. This can be overridden by the client.
"""
endpoint = HISTORICAL_COUNTRY.format(self.api_url, country)
endpoint = HISTORICAL_COUNTRY.format(self.api_url, country, last_days)
historical_stats = await self.request_client.make_request(endpoint)

return self._generate_history(historical_stats)


async def get_province_history(self, country, province):
async def get_province_history(self, country, province, last_days='all'):
"""
Get the historical data for a province within a country.
"""
endpoint = HISTORICAL_PROVINCE.format(self.api_url, country, province)
endpoint = HISTORICAL_PROVINCE.format(self.api_url, country, province, last_days)
data = await self.request_client.make_request(endpoint)

return self._generate_history(data)
Expand Down
7 changes: 4 additions & 3 deletions corona_api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
ALL_COUNTRIES = '{}/countries'
SORTED_COUNTRIES = '{}/countries?sort={}'
COUNTRY_DATA = '{}/countries/{}'
STATES = '{}/states'
HISTORICAL_COUNTRY = '{}/v2/historical/{}'
HISTORICAL_PROVINCE = '{}/v2/historical/{}/{}'
ALL_STATES = '{}/states'
SINGLE_STATE = '{}/states/{}'
HISTORICAL_COUNTRY = '{}/v2/historical/{}?lastdays={}'
HISTORICAL_PROVINCE = '{}/v2/historical/{}/{}?lastdays={}'
JHU_CSSE = '{}/v2/jhucsse'
JHU_CSSE_COUNTIES = '{}/v2/jhucsse/counties/{}'
YESTERDAY = '{}/yesterday'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
setup(
name = 'corona_api',
packages = ['corona_api'],
version = '0.6.3',
version = '0.6.4',
license='MIT',
description = 'An asynchronous wrapper for the corona.lmao.ninja API written in Python.',
long_description= long_desc,
Expand Down

0 comments on commit 59c9305

Please sign in to comment.