From 4c9c9bbcae3aba0fe13c2a43c2b8d8945d33082d Mon Sep 17 00:00:00 2001 From: Euan Date: Thu, 5 Oct 2023 20:13:51 +0100 Subject: [PATCH 1/2] Rankings call allows additional args --- sport80/sport80.py | 14 ++++++++++---- sport80/sport80_http_client.py | 9 +++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/sport80/sport80.py b/sport80/sport80.py index 367f0f1..4684bd8 100644 --- a/sport80/sport80.py +++ b/sport80/sport80.py @@ -8,6 +8,7 @@ class SportEighty: """ This class enables a variety of functions that can be carried out with a sport80 subdomain. """ + def __init__(self, subdomain: str, return_dict=True, debug: logging = logging.WARNING): self.__http_client = SportEightyHTTP(subdomain, return_dict=return_dict, debug_lvl=debug) @@ -35,10 +36,15 @@ def lifter_history(self, lifter_id: int) -> Union[list, dict]: """ Returns a dict containing a lifter history. The lifter_id does NOT correlate to the membership number """ return self.__http_client.get_lifter_data(lifter_id) - def rankings(self, wt_class: int, a_date: str, z_date: str, region: int) -> dict: - """ Returns a dict containing the rankings table for the specified weight class and date range """ - # todo: have this handle a kwargs dict instead of a bunch of args - return self.__http_client.get_rankings(wt_class, a_date, z_date, region) + def rankings(self, a_date: str, z_date: str, additional_args: dict = None) -> dict: + """ + Returns a dict containing the rankings for the given date range + :param a_date: Start date in format YYYY-MM-DD + :param z_date: End date in format YYYY-MM-DD + :param additional_args: Additional arguments such as weight category available from ranking_filters() + :return: dict of rankings + """ + return self.__http_client.get_rankings(a_date, z_date, additional_args) def ranking_filters(self): """ Pulls all the available ranking filters """ diff --git a/sport80/sport80_http_client.py b/sport80/sport80_http_client.py index 33cf394..569a973 100644 --- a/sport80/sport80_http_client.py +++ b/sport80/sport80_http_client.py @@ -95,11 +95,12 @@ def get_rankings_table(self, category, a_date, z_date, wt_class): get_page = self.http_session.get(api_url, headers=self.standard_headers) return get_page.json() - def get_rankings(self, wt_class: int, a_date: str, z_date: str, region: int): - """ Fetches the rankings table for the specified weight class and date range """ - # todo: have this handle a kwargs dict instead of a bunch of args + def get_rankings(self, a_date: str, z_date: str, additional_args=None) -> dict: + """ Returns a dict containing the rankings for the given date range """ api_url = urljoin(self.domain_env['RANKINGS_DOMAIN_URL'], EndPoint.ALL_RANKINGS.value + "?p=0&l=1000&sort=&d=&s=") - payload = {"date_range_start": a_date, "date_range_end": z_date, "weight_class": wt_class, "region": region} + payload = {"date_range_start": a_date, "date_range_end": z_date} + if additional_args: + payload.update(additional_args) get_page = self.http_session.post(api_url, headers=self.standard_headers, json=payload) if get_page.ok: return self.__collate_results(get_page.json()) From 59fb8cd5a04dea00f78b65dd3e6b80fffe85c7a5 Mon Sep 17 00:00:00 2001 From: Euan Date: Thu, 5 Oct 2023 20:15:35 +0100 Subject: [PATCH 2/2] Incremented version --- setup.py | 2 +- sport80/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 419386a..c850945 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name="sport80", - version="2.2.3", + version="2.2.4", description="Python API interface for the Sport80 sites", long_description='Intentionally empty', url="https://github.com/euanwm/sport80_api", diff --git a/sport80/__init__.py b/sport80/__init__.py index 41d300f..84d8d6a 100644 --- a/sport80/__init__.py +++ b/sport80/__init__.py @@ -7,5 +7,5 @@ from .helpers import pull_tables, convert_to_json, convert_to_py from .pages_enum import EndPoint -__version__ = "2.2.3" +__version__ = "2.2.4" __author__ = "Euan Meston"