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: Union[None, str]
|
||||||
device_controller_right = self.device_controller_right
|
device_controller_right = self.device_controller_right
|
||||||
|
|
||||||
leaderboard_player_info: Union[Unset, Dict[str, Any]] = UNSET
|
leaderboard_player_info: Union[Unset, Dict[str, Any], None] = UNSET
|
||||||
if not isinstance(self.leaderboard_player_info, 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()
|
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: Dict[str, Any] = {}
|
||||||
field_dict.update(
|
field_dict.update(
|
||||||
|
@ -7,6 +7,7 @@ from typing import Optional, Dict, Any
|
|||||||
from clients.scoresaber import client as scoresaber_client
|
from clients.scoresaber import client as scoresaber_client
|
||||||
from clients.scoresaber.api.players import get_api_player_player_id_scores
|
from clients.scoresaber.api.players import get_api_player_player_id_scores
|
||||||
from clients.scoresaber.models import PlayerScoreCollection
|
from clients.scoresaber.models import PlayerScoreCollection
|
||||||
|
from clients.scoresaber.models.get_api_player_player_id_scores_sort import GetApiPlayerPlayerIdScoresSort
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s %(levelname)s: %(message)s',
|
format='%(asctime)s %(levelname)s: %(message)s',
|
||||||
@ -57,7 +58,7 @@ class ScoreSaberAPI:
|
|||||||
player_id: str,
|
player_id: str,
|
||||||
use_cache: bool = True,
|
use_cache: bool = True,
|
||||||
limit: int = 100,
|
limit: int = 100,
|
||||||
sort: str = "recent",
|
sort: GetApiPlayerPlayerIdScoresSort = GetApiPlayerPlayerIdScoresSort.RECENT,
|
||||||
max_pages: Optional[int] = None
|
max_pages: Optional[int] = None
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
@ -92,11 +93,13 @@ class ScoreSaberAPI:
|
|||||||
limit=limit,
|
limit=limit,
|
||||||
sort=sort
|
sort=sort
|
||||||
)
|
)
|
||||||
except Exception as e:
|
logging.debug(f"Raw API response: {response}") # Log the raw response
|
||||||
logging.error(f"Error fetching page {page} for player {player_id}: {e}")
|
|
||||||
return {"metadata": {}, "playerScores": []}
|
|
||||||
|
|
||||||
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:
|
if total_items is None:
|
||||||
total_items = response.metadata.total
|
total_items = response.metadata.total
|
||||||
@ -109,8 +112,13 @@ class ScoreSaberAPI:
|
|||||||
|
|
||||||
page += 1
|
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 = {
|
result = {
|
||||||
'metadata': response.metadata.dict(),
|
'metadata': response.metadata.to_dict(),
|
||||||
'playerScores': all_scores
|
'playerScores': all_scores
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user