diff --git a/nhlpy/api/helpers.py b/nhlpy/api/helpers.py new file mode 100644 index 0000000..1b3ad72 --- /dev/null +++ b/nhlpy/api/helpers.py @@ -0,0 +1,29 @@ +from typing import List + +from nhlpy.http_client import HttpClient + + +class Helpers: + def __init__(self, http_client: HttpClient) -> None: + self.client = http_client + + def get_gameids_by_season(self, season: str, game_types: List[int] = None) -> List[str]: + """ + Get all gameids for a given season. + :param season: The season you want the gameids for. Format is YYYYYYYY. 20202021, 200232024, etc + :param game_types: List of game types you want to include. 2 is regular season, 3 is playoffs, 1 is preseason + """ + from nhlpy.api.teams import Teams + from nhlpy.api.schedule import Schedule + + teams = Teams(self.client).teams_info() + + gameids = [] + schedule_api = Schedule(self.client) + for team in teams: + schedule = schedule_api.get_season_schedule(team["abbr"], season) + for game in schedule["games"]: + if not game_types or game["gameType"] in game_types: + gameids.append(game["id"]) + + return gameids diff --git a/nhlpy/nhl_client.py b/nhlpy/nhl_client.py index f78b28e..cd91741 100644 --- a/nhlpy/nhl_client.py +++ b/nhlpy/nhl_client.py @@ -1,4 +1,4 @@ -from nhlpy.api import teams, standings, schedule, game_center, stats, misc, playoffs +from nhlpy.api import teams, standings, schedule, game_center, stats, misc, playoffs, helpers from nhlpy.http_client import HttpClient from nhlpy.config import ClientConfig @@ -36,3 +36,4 @@ def __init__( self.stats = stats.Stats(http_client=self._http_client) self.misc = misc.Misc(http_client=self._http_client) self.playoffs = playoffs.Playoffs(http_client=self._http_client) + self.helpers = helpers.Helpers(http_client=self._http_client) diff --git a/pyproject.toml b/pyproject.toml index 1007fcb..5ec43d6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "nhl-api-py" -version = "2.16.0" +version = "2.17.0" description = "NHL API (Updated for 2024/2025) and EDGE Stats. For standings, team stats, outcomes, player information. Contains each individual API endpoint as well as convience methods as well as pythonic query builder for more indepth EDGE stats." authors = ["Corey Schaf "] readme = "README.md"