Skip to content

Commit

Permalink
Fixed paging issue
Browse files Browse the repository at this point in the history
  • Loading branch information
euanwm committed Oct 8, 2023
1 parent 124af7b commit 81e9a6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions sport80/sport80.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ 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, a_date: str, z_date: str, additional_args: dict = None) -> dict:
def rankings(self, a_date: str, z_date: str, additional_args: dict = None) -> list[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: List of dicts containing the rankings
"""
return self.__http_client.get_rankings(a_date, z_date, additional_args)

Expand Down
10 changes: 7 additions & 3 deletions sport80/sport80_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,19 @@ 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, a_date: str, z_date: str, additional_args=None) -> dict:
def get_rankings(self, a_date: str, z_date: str, additional_args=None) -> list[dict]:
""" Returns a dict containing the rankings for the given date range """
results = []
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}
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())
front_page = get_page.json()
collated_pages = self.__collate_results(front_page, payload)
results = [item for sublist in collated_pages.values() for item in sublist['data']]
return results

def get_ranking_filters(self):
api_url = urljoin(self.domain_env['RANKINGS_DOMAIN_URL'], "/api/categories/rankings/table")
Expand Down Expand Up @@ -139,7 +143,7 @@ def __collate_results(self, page_one: dict, payload: Optional[dict] = None) -> d
all_pages = {0: page_one}
current_page = page_one
index = 1
while current_page['next_page_url']:
while current_page['next_page_url'] is not None:
all_pages[index] = current_page = self.__next_page(current_page['next_page_url'], payload)
index = index + 1
return all_pages
Expand Down

0 comments on commit 81e9a6b

Please sign in to comment.