dword4 / nhlapi

Documenting the publicly accessible portions of the NHL API
448 stars 56 forks source link

live game data #24

Closed edwardz8 closed 2 years ago

edwardz8 commented 2 years ago

not an issue but was asked to put my question in the issues section of github.

i asked once but can’t find it now and don’t believe i received an answer. perhaps i’m overlooking it. but i’m wondering:

how do you retrieve live game data for a specific day? i found one example in the documentation but the number variable in the url throws me off and i haven’t been able to find specific dates because, let’s say for example: a variable like 11022021 returns a game from september if this year. im not sure if that’s the exact number cause i’m not looking at the url or the live game data example provided in the docs at the moment, but hopefully i’m explaining myself clear enough!

i would definitely like to contribute to the docs once this is resolved so others won’t have the same issue in the future. 📝

any assistance would be appreciated 🏒😀

dword4 commented 2 years ago

When you say live game data do you mean such as the specific endpoint https://statsapi.web.nhl.com/api/v1/game/ID/feed/live or just a list of data containing games that are current live for the specified day?

In the first case I do not believe it would be possible to pull all that data for every game scheduled that day, you would have to loop through the list of GameIDs for that day and request each separately. Doing such a large request would probably create significant load on the API servers as a single game can return several thousand lines of data each call, so all the games would be a lot to parse through.

In the second case there may be a way using the cayenneExp= expression to filter a schedule request however I haven't quite worked out how that would look just yet, I tried a few different things this evening and none seemed to work yet.


Lets take a look at that endpoint I mentioned up above for a second to see if maybe I can explain it better. A current fully functional call would be like this https://statsapi.web.nhl.com/api/v1/game/2021020274/feed/live which is Flames/Bruins for 2021-11-22. Game IDs are actually two separate values put together, the first four digits are the year [2021] and the rest is the unique ID for that game, in this case [020274]. As far as I can tell there is no real pattern to the unique ID other than it just is incremented.

edwardz8 commented 2 years ago

ok i understand -- i had overlooked how the games are incremented.

since live game data would be pretty heavy on the api -- a very interesting problem, but maybe it could partially be solved by only calling the api for a specific live game every 5 minutes or so and not every time a change is made -- i guess an alternative and simpler approach for my use case could be just to get the boxscore: https://statsapi.web.nhl.com/api/v1/game/2021020280/boxscore and increment the game id.

thanks for the explanation 🏒