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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
.https://praw.readthedocs.io/en/latest/getting_started/configuration/options.html#miscellaneous-configuration-options