From ba1719b9d53bd9ea0a7ea3b282d85fab8b573daf Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Tue, 8 Oct 2024 23:20:18 +0100 Subject: [PATCH 1/5] Check if bracket actually has data data before returning object --- sendou/models/tournament/tournament.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sendou/models/tournament/tournament.py b/sendou/models/tournament/tournament.py index b3390ab..980590a 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("stage", []): + return return Bracket(data, self._request_client) async def get_standings(self) -> List[BracketStanding]: From 32c880b78ebd04025194e2c80b60b00bbc55d224 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Tue, 8 Oct 2024 23:21:10 +0100 Subject: [PATCH 2/5] Init BracketMatch op2 to None if data not existant --- sendou/models/tournament/bracket/bracket.py | 6 ++++++ 1 file changed, 6 insertions(+) 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]: """ From d8fc5fad79c2f99cef858a9da69ee0c93e55d7e4 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Tue, 8 Oct 2024 23:21:35 +0100 Subject: [PATCH 3/5] Standing stats are optional --- sendou/models/tournament/bracket/Standing.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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: From a826c6f0fc61b7a01d792d9178af60dff239b356 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Tue, 8 Oct 2024 23:21:41 +0100 Subject: [PATCH 4/5] bump version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From f245f2fce8295cc29071724e39d89ceb401ce8a7 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Tue, 8 Oct 2024 23:24:13 +0100 Subject: [PATCH 5/5] use 'match' as indicator is no bracket data exists --- sendou/models/tournament/tournament.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sendou/models/tournament/tournament.py b/sendou/models/tournament/tournament.py index 980590a..8c42da0 100644 --- a/sendou/models/tournament/tournament.py +++ b/sendou/models/tournament/tournament.py @@ -69,7 +69,7 @@ async def get_bracket_data(self) -> Optional[Bracket]: """ 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("stage", []): + if not data.get("match", []): return return Bracket(data, self._request_client)