diff --git a/src/clients/scoresaber/models/score.py b/src/clients/scoresaber/models/score.py index 877df58..5c992b9 100644 --- a/src/clients/scoresaber/models/score.py +++ b/src/clients/scoresaber/models/score.py @@ -98,9 +98,11 @@ class Score: device_controller_right: Union[None, str] device_controller_right = self.device_controller_right - leaderboard_player_info: Union[Unset, Dict[str, Any]] = UNSET - if not isinstance(self.leaderboard_player_info, Unset): + leaderboard_player_info: Union[Unset, Dict[str, Any], None] = UNSET + if self.leaderboard_player_info is not None and hasattr(self.leaderboard_player_info, 'to_dict'): leaderboard_player_info = self.leaderboard_player_info.to_dict() + elif self.leaderboard_player_info is None: + leaderboard_player_info = None field_dict: Dict[str, Any] = {} field_dict.update( diff --git a/src/helpers/ScoreSaberAPI.py b/src/helpers/ScoreSaberAPI.py index d6a640f..8db0533 100644 --- a/src/helpers/ScoreSaberAPI.py +++ b/src/helpers/ScoreSaberAPI.py @@ -7,6 +7,7 @@ from typing import Optional, Dict, Any from clients.scoresaber import client as scoresaber_client from clients.scoresaber.api.players import get_api_player_player_id_scores from clients.scoresaber.models import PlayerScoreCollection +from clients.scoresaber.models.get_api_player_player_id_scores_sort import GetApiPlayerPlayerIdScoresSort logging.basicConfig( format='%(asctime)s %(levelname)s: %(message)s', @@ -57,7 +58,7 @@ class ScoreSaberAPI: player_id: str, use_cache: bool = True, limit: int = 100, - sort: str = "recent", + sort: GetApiPlayerPlayerIdScoresSort = GetApiPlayerPlayerIdScoresSort.RECENT, max_pages: Optional[int] = None ) -> Dict[str, Any]: """ @@ -92,25 +93,32 @@ class ScoreSaberAPI: limit=limit, sort=sort ) + logging.debug(f"Raw API response: {response}") # Log the raw response + + # Check if response is a string (error message) instead of PlayerScoreCollection + if isinstance(response, str): + raise ValueError(f"Unexpected string response: {response}") + + all_scores.extend([score.to_dict() for score in response.player_scores]) + + if total_items is None: + total_items = response.metadata.total + logging.debug(f"Total scores to fetch: {total_items}") + + logging.debug(f"Fetched page {page}: {len(response.player_scores)} scores") + + if len(all_scores) >= total_items: + break + + page += 1 + except Exception as e: logging.error(f"Error fetching page {page} for player {player_id}: {e}") + logging.exception("Detailed traceback:") # This will log the full traceback return {"metadata": {}, "playerScores": []} - all_scores.extend([score.dict() for score in response.player_scores]) - - if total_items is None: - total_items = response.metadata.total - logging.debug(f"Total scores to fetch: {total_items}") - - logging.debug(f"Fetched page {page}: {len(response.player_scores)} scores") - - if len(all_scores) >= total_items: - break - - page += 1 - result = { - 'metadata': response.metadata.dict(), + 'metadata': response.metadata.to_dict(), 'playerScores': all_scores }