Skip to content

Commit

Permalink
Merge pull request #10 from euanwm/feature/rankings_additional_payload
Browse files Browse the repository at this point in the history
Feature/rankings additional payload
  • Loading branch information
euanwm authored Oct 5, 2023
2 parents 84c2804 + 59fb8cd commit e0cb1b6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion sport80/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
14 changes: 10 additions & 4 deletions sport80/sport80.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 """
Expand Down
9 changes: 5 additions & 4 deletions sport80/sport80_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit e0cb1b6

Please sign in to comment.