Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Helpers module. #93

Merged
merged 3 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading