Skip to content

Instantly share code, notes, and snippets.

@bboe
Last active June 7, 2021 06:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bboe/1860715 to your computer and use it in GitHub Desktop.
Save bboe/1860715 to your computer and use it in GitHub Desktop.
Python Reddit API Comment Loop Test
#!/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())
@bboe
Copy link
Author

bboe commented Jun 7, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment