Fix scoresaber oldscores strategy.

This commit is contained in:
Brian Lee 2024-10-16 08:59:17 -07:00
parent 283853d2c4
commit 92707add36
2 changed files with 27 additions and 17 deletions

View File

@ -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(

View File

@ -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,11 +93,13 @@ class ScoreSaberAPI:
limit=limit,
sort=sort
)
except Exception as e:
logging.error(f"Error fetching page {page} for player {player_id}: {e}")
return {"metadata": {}, "playerScores": []}
logging.debug(f"Raw API response: {response}") # Log the raw response
all_scores.extend([score.dict() for score in response.player_scores])
# 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
@ -109,8 +112,13 @@ class ScoreSaberAPI:
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": []}
result = {
'metadata': response.metadata.dict(),
'metadata': response.metadata.to_dict(),
'playerScores': all_scores
}