Last active
June 7, 2021 06:26
-
-
Save bboe/1860715 to your computer and use it in GitHub Desktop.
Python Reddit API Comment Loop Test
This file contains 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
#!/usr/bin/env python3 | |
import logging | |
import sys | |
import time | |
import praw | |
def configure_logging(): | |
logger = logging.getLogger("praw") | |
logger.setLevel(logging.DEBUG) | |
logger.addHandler(logging.StreamHandler()) | |
def main(): | |
configure_logging() | |
reddit = praw.Reddit("SITENAME", user_agent="PRAW loop test") | |
reddit.config.ratelimit_seconds = 0xFFFF | |
last = time.time() | |
subreddit = reddit.subreddit("test") | |
for i, submission in enumerate(subreddit.new()): | |
submission.reply(f"Test comment: {i}") | |
now = time.time() | |
print(f"{now - last:.2f} {i:2d} {submission.title}") | |
last = now | |
if __name__ == "__main__": | |
sys.exit(main()) |
Thanks everyone for the updates. I updated the gist to work with Python 3.6+ and PRAW 7.0+ where PRAW has built-in support for retries based upon the configuration value ratelimit_seconds
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ok I just noticed this as of June 2021 but they have changed the message in their error message so that the above code will no longer work. My guess is they do this every so often to deter old bots that are no longer updated from using this method of retry. The new message reads like so:
"Looks like you've been doing that a lot. Take a break for 37 seconds before trying again."
And the above code can be modified like so to make it work
My personal solution to this uses regex and looks like