Fix scoresaber oldscores strategy.
This commit is contained in:
parent
283853d2c4
commit
92707add36
@ -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(
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user