diff --git a/pyproject.toml b/pyproject.toml index c8d2743..be26548 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "sendou-py" -version = "1.2.2" +version = "1.2.3" description = "An async Python library for Sendou.ink" authors = [ "Vincent Lee ",] license = "MIT" diff --git a/sendou/models/tournament/bracket/Standing.py b/sendou/models/tournament/bracket/Standing.py index d3dbe7f..c616892 100644 --- a/sendou/models/tournament/bracket/Standing.py +++ b/sendou/models/tournament/bracket/Standing.py @@ -73,12 +73,15 @@ class BracketStanding: """ tournament_team_id: int placement: int - stats: StandingStats + stats: Optional[StandingStats] def __init__(self, data: dict): self.tournament_team_id = data.get("tournamentTeamId", 0) self.placement = data.get("placement", 0) - self.stats = StandingStats.from_dict(data.get("stats", {})) + if stats := data.get("stats", {}): + self.stats = StandingStats.from_dict(stats) + else: + self.stats = None @staticmethod def api_route(**kwargs) -> str: diff --git a/sendou/models/tournament/bracket/bracket.py b/sendou/models/tournament/bracket/bracket.py index 827daff..b6ed388 100644 --- a/sendou/models/tournament/bracket/bracket.py +++ b/sendou/models/tournament/bracket/bracket.py @@ -215,13 +215,19 @@ def __init__(self, data: dict, request_client: RequestsClient): self.opponent1 = BracketMatchOpponent(data.get("opponent1", {})) if data.get("opponent2", {}): self.opponent2 = BracketMatchOpponent(data.get("opponent2", {})) + else: + self.opponent2 = None self.round_id = data.get("round_id", 0) self.stage_id = data.get("stage_id", 0) self.status = data.get("status", 0) if data.get("lastGameFinishedAt", None): self.lastGameFinishedAt = datetime.fromtimestamp(data.get("lastGameFinishedAt", 0), tz=timezone.utc) + else: + self.lastGameFinishedAt = None if data.get("createdAt", None): self.createdAt = datetime.fromtimestamp(data.get("createdAt", 0), tz=timezone.utc) + else: + self.createdAt = None async def get_match(self) -> Optional[Match]: """ diff --git a/sendou/models/tournament/tournament.py b/sendou/models/tournament/tournament.py index b3390ab..8c42da0 100644 --- a/sendou/models/tournament/tournament.py +++ b/sendou/models/tournament/tournament.py @@ -58,15 +58,19 @@ def __init__(self, data: dict, index: int, tournament_id: int, request_client: R self._index = index self.__tournament_id = tournament_id - async def get_bracket_data(self) -> Bracket: + async def get_bracket_data(self) -> Optional[Bracket]: """ - Get the detailed bracket data + Get the detailed bracket data, if bracket has details. + + *Here are cases where Brackets haven't been played so no data exists* Returns: - (Bracket): Bracket Data + (Optional[Bracket]): Bracket Data """ path = Bracket.api_route(tournament_id=self.__tournament_id, bracket_index=self._index) data = await self._request_client.get_response(path) + if not data.get("match", []): + return return Bracket(data, self._request_client) async def get_standings(self) -> List[BracketStanding]: