Skip to content

Commit

Permalink
Feature: Helpers module. (#93)
Browse files Browse the repository at this point in the history
* Feature: Helpers module.
- Contains useful but often expiremental methods for aggregation and analysis
  • Loading branch information
coreyjs authored Dec 9, 2024
1 parent a354661 commit de2a514
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
29 changes: 29 additions & 0 deletions nhlpy/api/helpers.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion nhlpy/nhl_client.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit de2a514

Please sign in to comment.