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

Get League Schedule for the entire Season #92

Closed
Btibert3 opened this issue Dec 7, 2024 · 4 comments · Fixed by #93
Closed

Get League Schedule for the entire Season #92

Btibert3 opened this issue Dec 7, 2024 · 4 comments · Fixed by #93
Assignees

Comments

@Btibert3
Copy link

Btibert3 commented Dec 7, 2024

Is your feature request related to a problem? Please describe.
It appears that there are various ways to slice out schedules; for a given day, for a team, a week, but not the entire season across the league. At first blush I expected this using the .get_season_schedule method but that requires a team id.

Describe the solution you'd like
An approach similar to .get_season_schedule but for the entire league. My use case would be to grab the gameids for a season in order to grab the results and PBP datasets for historical analysis and modeling. As such, my need isn't the full object, but simply a list of gameids, but admittedly that might be too narrow. My framing is an endpoint that I previously used from here: http://www.nicetimeonice.com/api, which would yield an array of gameids.

Describe alternatives you've considered
I could walk or daily schedules.

Additional context

@coreyjs
Copy link
Owner

coreyjs commented Dec 9, 2024

This is one of those endpoints where there just isn't a clean implementation from the NHL. They build all these separate endpoints to facilitate their web site and from an API standpoint they are confusing and kinda suck. I think there are two solutions here.

  1. I use to have a section called helpers where I would put methods like this in there. Ones that did lots of aggregation or called another endpoint many times. Might be beneficial to have something like client.helpers.get_gameids_by_season(year) or such.

  2. The only way to do this now is to get all team abbreviations from client.teams.team_info() and loop get_season_schedule(team). This is essentially what I would do in option 1.

@coreyjs coreyjs linked a pull request Dec 9, 2024 that will close this issue
@coreyjs
Copy link
Owner

coreyjs commented Dec 9, 2024

This connected PR should add this. It's basically just the following which returns 2835 games ids. Filtered to just regular season is 2624.

    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 = []
        for team in teams:
            schedule = Schedule(self.client).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

@coreyjs coreyjs self-assigned this Dec 9, 2024
@coreyjs
Copy link
Owner

coreyjs commented Dec 9, 2024

released in ver 2.17.0

@Btibert3
Copy link
Author

Btibert3 commented Dec 9, 2024

🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants