bttmly / nba

Node.js client for nba.com API endpoints
MIT License
710 stars 180 forks source link

List of Teams & Games #79

Closed tylerehc closed 4 years ago

tylerehc commented 4 years ago

It'd be great to add some high level queries like a list of all teams in the league or a list of all games for a given team.

For all games, for example, it looks like there's an endpoint for scores: /data/10s/v2015/json/mobile_teams/nba/2019/scores/

bttmly commented 4 years ago

The new /data endpoints are definitely where its at, I haven't had time to add them. Would definitely welcome a PR for scores! (check out this file to see how they're implemented https://github.com/bttmly/nba/blob/master/src/data.js)

For teams, this library actually comes packaged with some info on each team, nba.teams – its an array of objects that look like this

> nba.teams[16]
{ teamId: 1610612749,
  abbreviation: 'MIL',
  teamName: 'Milwaukee Bucks',
  simpleName: 'Bucks',
  location: 'Milwaukee' }

Also a list of current players, updated sporadically when I think to do it, is also available under nba.players (EDIT: I just updated the built-in players list now, in nba@4.11.1). The reason these are included is that many queries require a team id or player id and having to do an initial call to figure that out is really annoying. There are also some helpers built in to make searching easy: nba.findPlayer returns objects like this (same stuff thats in nba.players)

> nba.findPlayer("kawhi")
{ firstName: 'Kawhi',
  lastName: 'Leonard',
  playerId: 202695,
  teamId: 1610612759,
  fullName: 'Kawhi Leonard',
  downcaseName: 'kawhi leonard' }

there is also teamIdFromName and playerIdFromName

> nba.teamIdFromName("bucks")
1610612749

the searching functionality is pretty basic.

At runtime, like when your code starts, you can also do nba.updatePlayers() to refresh the nba.players list with the most recent list of active NBA players.

bttmly commented 4 years ago

@tylerehc you got a full URL for that scores endpoint?

tylerehc commented 4 years ago

Appears it's only for today's scores:

https://data.nba.com/data/10s/v2015/json/mobile_teams/nba/__season__/scores/00_todays_scores.json

I've been trying variations to see if there's a yet-unused endpoint in the works, but no luck yet.

And full season boxscores are still on the stats.nba endpoints:

https://stats.nba.com/team/1610612749/boxscores/?Season=2018-19&SeasonType=Regular%20Season

bttmly commented 4 years ago

Ok thanks, I'll get something in soon. I'm writing a crawler that uses puppeteer to scan nba.com and record HTTP requests so I can discover more API endpoints, but its not turning up too much so far. It seems like a lot of their APIs are used internally to generate HTML and are not exposed at the edge.