Hi! Not sure if I’m going to be able to get any help with this one, since it’s for a specific library, but I’m having some trouble with pybaseball (and in specific, being rate limited by it). I’m calling the function pybaseball.schedule_and_record() in order to get data to create a graph of team W/L data, and up until now I’ve been able to do this no problem, and generate as many charts as I desire.
Recently, I’ve expanded my code to also be able to graph divisions. To do this, I send a separate request for each team in the division. Again, I’ve been able to do this as much as I desire.
The problem arose when I tried to optimize the division graphing, since sending all 5 of those requests was taking upwards of 30 seconds to complete. I tried to speed this up by using multithreading to send all of those requests at once, which worked like a charm! However after generating about 5 or 6 graphs within the course of about a half hour, I was rate limited. (Unhelpfully, pybaseball did not tell me this, and instead spit out a value error).
My question now is: what do I do to avoid being rate limited? Do I have to run the requests in a single threaded fashion?
Also typing this out, I do realize that pybaseball does have the option to keep a cache, though if I rely on that, my data won’t be updated with new games as they are played. Should I be keeping and purging a cache at regular intervals? And if so, how would I go about keeping track of when to purge? I imagine I’d have to keep a timestamp in some sort of log file, maybe with shelf?