Skip to content

Commit

Permalink
- fix models: Event, Match, Player (#10)
Browse files Browse the repository at this point in the history
- split round_info into round_info_by_event and round_info_by_season
 - add functionality: upcoming_matches, results_from_last_days, head_to_head
  • Loading branch information
TarnishingColors authored Nov 14, 2023
1 parent 97a3868 commit 3ae3b70
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
55 changes: 52 additions & 3 deletions snooker/api/snooker_org.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Type # noqa
from typing import List, Optional, Type, Literal # noqa

from snooker.api.base import BaseApi
from snooker.models.snooker_org.event import Event
Expand Down Expand Up @@ -121,7 +121,7 @@ def event_players(self, event_id: int) -> Optional[List[Player]]:

return self._get_two_dimensional(params, model)

def players(self, status: Optional[str], season: Optional[int]) -> Optional[List[Player]]:
def players(self, status: Literal['a', 'p'], season: Optional[int]) -> Optional[List[Player]]:
"""
Retrieve list of all players in the tour in given season.
Expand All @@ -147,7 +147,7 @@ def rankings(self, ranking_type: str, season: int) -> Optional[List[Ranking]]:

return self._get_two_dimensional(params, model)

def round_info(self, event_id: int) -> Optional[List[Round]]:
def round_info_by_event(self, event_id: int) -> Optional[List[Round]]:
"""
Retrieve round info for particular event.
Expand All @@ -159,6 +159,18 @@ def round_info(self, event_id: int) -> Optional[List[Round]]:

return self._get_two_dimensional(params, model)

def round_info_by_season(self, season: Optional[int]) -> Optional[List[Round]]:
"""
Retrieve round info for particular season.
:param season: ID of a season for which data will be collected (current season if no season provided)
:return: List of rounds (if available)
"""
params = {'t': 12, 's': season}
model = Round

return self._get_two_dimensional(params, model)

def event_seeding(self, event_id: int) -> Optional[List[Seeding]]:
"""
Retrieve info regarding player seedings for an event.
Expand All @@ -170,3 +182,40 @@ def event_seeding(self, event_id: int) -> Optional[List[Seeding]]:
model = Seeding

return self._get_two_dimensional(params, model)

def upcoming_matches(self) -> Optional[List[Match]]:
"""
Retrieve upcoming matches.
:return: List of upcoming matches (if available)
"""
params = {'t': 14}
model = Match

return self._get_two_dimensional(params, model)

def results_from_last_days(self, number_of_days: int = 0) -> Optional[List[Match]]:
"""
Retrieve results from the last few days. There is a limit of 500 results returned.
:param number_of_days: number of last days to retrieve results for
:return: List of matches (If available)
"""
params = {'t': 15, 'ds': number_of_days}
model = Match

return self._get_two_dimensional(params, model)

def head_to_head(self, player_1_id: int, player_2_id: int, season: Optional[int]) -> Optional[List[Match]]:
"""
Retrieve info regarding a player.
:param player_1_id: ID of a first player
:param player_2_id: ID of a second player
:param season: Season for which data is collected. Use -1 for all seasons (current season if no season provided).
:return: List of matches (if available)
"""
params = {'p1': player_1_id, 'p2': player_2_id, 's': season}
model = Match

return self._get_two_dimensional(params, model)
1 change: 1 addition & 0 deletions snooker/models/snooker_org/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ class Event(JsonModel):
CommonNote: str
DefendingChampion: int
PreviousEdition: int
Tour: str
3 changes: 3 additions & 0 deletions snooker/models/snooker_org/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Match(JsonModel):
WinnerID: int
Unfinished: bool
OnBreak: bool
Status: int
WorldSnookerID: int
LiveUrl: str
DetailsUrl: str
Expand All @@ -39,3 +40,5 @@ class Match(JsonModel):
Sessions: str
Note: str
ExtendedNote: str
HeldOver: bool
StatsURL: str
3 changes: 3 additions & 0 deletions snooker/models/snooker_org/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ class Player(JsonModel):
FirstSeasonAsPro: int
LastSeasonAsPro: int
Info: str
NumRankingTitles: int
NumMaximums: int
Died: str

0 comments on commit 3ae3b70

Please sign in to comment.