Created
October 10, 2020 23:47
-
-
Save sticks-stuff/62a6ad7d20b8faa1beb8cb49d8b4eb3d to your computer and use it in GitHub Desktop.
PRAW RateLimit Wrapper - Auto-retry functions that get rate-limited by reddit after the ratelimit is over - wrap your functions in handle_ratelimit()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def handle_ratelimit(func, *args, **kwargs): | |
while True: | |
try: | |
func(*args, **kwargs) | |
break | |
except praw.exceptions.RedditAPIException as exception: | |
totalLength = str(exception.items[0].message).split('you are doing that too much. try again in ', 1)[1] | |
minutesToSleep = totalLength[0].partition("minutes.")[0] | |
secondsToSleep = int(minutesToSleep) * 60 | |
print("Sleeping for " + str(secondsToSleep) + " seconds") | |
time.sleep(secondsToSleep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment