nba_api icon indicating copy to clipboard operation
nba_api copied to clipboard

API request takes too long, is there a way to request only part of an endpoint?

Open panosp1705 opened this issue 5 years ago • 2 comments

Hi all, I am currently writing a simulation program for my website and am currently so pleased with the API, however, when trying to gather the points that a team has scored and the points scored against them for a particular game the only endpoint I can find that does that is winprobabilityPBP. However, for my simulation, I need to query the API for every game in a season and the data sent back from the API is too big as it also contains details on every play in the game. Is there a way to request the API but it only return one of the lists instead of the details of each play and also the smaller point stats. As the query takes way too long to be useable. Thanks

PS. here is the code

https://pastebin.com/wNyVM3uV

panosp1705 avatar Aug 30 '20 13:08 panosp1705

@panosp1705 - I think you are seeing a time out. The NBA will throttle you for continuous calls. The first dozen or so will get through and then the throttle kicks in. Within your calls to the NBA api add time.sleep(.600) I've found that to be the best amount of time and can loop through seasons of data. I have done a lot of work with the NBA's play by play feed and with the timeout I can loop over multiple seasons of data.

I tested portions of your calls and when I called WinProbabilityPBP I only ended up with 44 bytes on the call. Game ID was 0021901311. So the data is very small.

game1_scores = winprobabilitypbp.WinProbabilityPBP(game_id=game_id1[0], timeout=1000).get_dict()['resultSets'][1]['rowSet']

print(sys.getsizeof(game1_scores))

44

rsforbes avatar Sep 04 '20 15:09 rsforbes

I was having issues with time outs when iterating through playbyplay requests for an entire season and time.sleep(.600) on each iteration fixed it perfectly. Thank you

lukegeorge85 avatar Feb 17 '21 11:02 lukegeorge85