Closed alexanderadavid closed 4 years ago
Huh! I hadn't considered that. Do you have some examples of full URLs for WNBA API requests?
Whatever powers stats.nba.com must also power stats.wnba.com. From what I've seen all requests and UI are the same.
The first request when visiting Doncic's player dashboard at https://stats.nba.com/player/1629029/
and the first request when visiting Jordin Canada's dashboard at https://stats.wnba.com/player/1628886/
Here is a play by play request for an nba game https://stats.nba.com/game/0021900821/playbyplay/
and for a wnba game https://stats.wnba.com/game/1021900187/playbyplay/
At a glance, it might be as easy as finding an elegant way to fit a "w" into the url.
if it's just a matter of hitting a different domain, this should be very easy to implement. the wnba
package is available.
maybe this is primarily an issue of how to manage two packages. i know Lerna exists, but i don't know much past that. it might be overkill in this situation.
I was planning to just add a configurable domain parameter. This would also help in cases where you want to run a proxy server e.g. to get around CORS restrictions or what-have-you.
FWIW you can do this with the library as-is – you can swap out the transport layer like so
const nba = require("nba");
const getJSON = require("nba/src/get-json");
const transport = (url, params, options) => {
// simply swap the host and then defer the rest to the built in getJSON function
const fixedURL = url.replace("stats.nba.com", "stats.wnba.com");
return getJSON(fixedURL, params, options);
};
// create a new stats client here with our WNBA transport
const wnbaStats = nba.stats.withTransport(transport);
(async () => {
const result = await wnbaStats.playerInfo({ PlayerID: "1628886" });
console.log(result);
})();
Just tested this and it works. The signature of a transport function is url, query params as object, and a flexible options object as the optional final argument. One gotcha is that NBA.com requires some headers to be present, you can copy the ones I use from there https://github.com/bttmly/nba/blob/master/src/get-json.js#L5-L14
withTransport()
is sufficient for my needs. Thanks for the help!
btw - it looks like the G League is the same story: https://stats.gleague.nba.com
Very cool. Might be worth adding these details to the readme.
Added!
It seems like the WNBA uses the same or very similar infrastructure as the NBA stats API:
https://stats.wnba.com/
Have you thought about building some abstraction to fit WNBA alongside NBA or building a new repo alltogether? I would be interested in taking a crack at it.