Skip to content

Commit 73dcf41

Browse files
committed
Add support for calendar endpoint
1 parent a3ecb86 commit 73dcf41

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed

sendou/client.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict, List, Optional, Union
22
from datetime import datetime, timedelta
33
from aiohttp_client_cache import CacheBackend
4-
from sendou.models import User, Tournament, Match
4+
from sendou.models import User, Tournament, Match, CalendarEntry
55
from sendou.requests import RequestsClient
66

77

@@ -76,6 +76,21 @@ async def run():
7676
data = await self.__client.get_response(path)
7777
return User(data, self.__client)
7878

79+
async def get_calendar(self, year: str, month: str) -> List[CalendarEntry]:
80+
"""
81+
Get Sendou.ink calendar
82+
83+
Attributes:
84+
year: Year
85+
month: Month
86+
87+
Returns:
88+
(List[CalendarEntry]): Calendar Entries
89+
"""
90+
path = CalendarEntry.api_route(year=year, month=month)
91+
data = await self.__client.get_response(path)
92+
return [CalendarEntry(entry, self.__client) for entry in data]
93+
7994
async def get_tournament(self, tournament_id: str) -> Optional[Tournament]:
8095
"""
8196
Get Sendou.ink tournament
@@ -88,7 +103,7 @@ async def get_tournament(self, tournament_id: str) -> Optional[Tournament]:
88103
"""
89104
path = Tournament.api_route(tournament_id=tournament_id)
90105
data = await self.__client.get_response(path)
91-
return Tournament(tournament_id, data, self.__client)
106+
return Tournament(int(tournament_id), data, self.__client)
92107

93108
async def get_tournament_matches(self, match_id: str) -> Optional[Match]:
94109
"""

sendou/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
from .badge import Badge
88
from .plusServer import PlusTiers
99
from .stageMapList import Stage, ModeShort, StageWithMode
10+
from .calendarEntry import CalendarEntry
1011

sendou/models/calendarEntry.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from .baseModel import BaseModel
2+
from sendou.requests import RequestsClient
3+
from typing import Optional
4+
from datetime import datetime
5+
from dateutil import parser
6+
7+
from .tournament import Tournament
8+
9+
10+
class CalendarEntry(BaseModel):
11+
"""
12+
Calendar Entry Model
13+
14+
Attributes:
15+
name (str): Event Name
16+
tournament_id (int): Tournament ID
17+
tournament_url (str): Tournament URL
18+
start_time (datetime): Event Start Time
19+
"""
20+
name: str
21+
tournament_id: Optional[int]
22+
tournament_url: Optional[str]
23+
start_time: datetime
24+
25+
def __init__(self, data: dict, request_client: RequestsClient):
26+
super().__init__(data, request_client)
27+
self.name = data.get("name", "")
28+
self.tournament_id = data.get("tournamentId", None)
29+
self.tournament_url = data.get("tournamentUrl", "")
30+
self.start_time = parser.parse(data.get("startTime", ""))
31+
32+
@staticmethod
33+
def api_route(**kwargs) -> str:
34+
"""
35+
API Route
36+
Args:
37+
year (str): Year
38+
month (str): Month
39+
40+
Returns:
41+
str: API Route
42+
"""
43+
return f"api/calendar/{kwargs.get('year')}/{kwargs.get('month')}"
44+
45+
async def get_tournament(self) -> Optional[Tournament]:
46+
"""
47+
Get the tournament for the calendar entry
48+
Returns:
49+
(Optional[Tournament]): Tournament
50+
"""
51+
if self.tournament_id is None:
52+
return None
53+
path = Tournament.api_route(tournament_id=self.tournament_id)
54+
data = await self._request_client.get_response(path)
55+
return Tournament(self.tournament_id, data, self._request_client)
56+
57+
def __repr__(self):
58+
return f"<CalendarEntry name={self.name} | tournament_id={self.tournament_id} | start_time={self.start_time}>"

sendou/models/tournament/tournament.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ class TournamentBracket(BaseModel):
5252
type (BracketType): Bracket Type
5353
name (str): Bracket Name
5454
_index (int): Bracket Index
55-
__tournament_id (str): Tournament ID
55+
__tournament_id (int): Tournament ID
5656
"""
5757
type: BracketType
5858
name: str
5959
_index: int
60-
__tournament_id: str
60+
__tournament_id: int
6161

62-
def __init__(self, data: dict, index: int, tournament_id: str, request_client: RequestsClient):
62+
def __init__(self, data: dict, index: int, tournament_id: int, request_client: RequestsClient):
6363
"""
6464
Init
6565
:param data: Raw data from API
@@ -98,15 +98,15 @@ class Tournament(BaseModel):
9898
teams (TournamentTeamInfo): Tournament Team Info
9999
brackets (List[TournamentBracket]): Tournament Brackets
100100
"""
101-
id: str
101+
id: int
102102
name: str
103103
url: str
104104
logo_url: Optional[str]
105105
start_time: datetime
106106
teams: TournamentTeamInfo
107107
brackets: List[TournamentBracket]
108108

109-
def __init__(self, id: str, data: dict, request_client: RequestsClient):
109+
def __init__(self, id: int, data: dict, request_client: RequestsClient):
110110
"""
111111
Init
112112

0 commit comments

Comments
 (0)