Created
February 12, 2020 21:28
-
-
Save jarhill0/4b64ece572b2304f8073c2319ad445df to your computer and use it in GitHub Desktop.
Checking for multiple exceptions.
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
import praw | |
SUB_NAME = "###" | |
# ^ This name should be a subreddit that only allows link posts and not | |
# self posts. Preferably you should mod it (but not with the account | |
# that you run this script as), because it is going to get spammed. | |
reddit = praw.Reddit() # fill in | |
subreddit = reddit.subreddit(SUB_NAME) | |
for x in range(50): | |
try: | |
subreddit.submit(str(x), url=f'https://duckduckgo.com/?q={x}') | |
except praw.exceptions.APIException as e: | |
assert e.error_type == 'RATELIMIT' | |
print(f'Successfully post rate-limited in {SUB_NAME}') | |
break | |
subreddit.submit('Hello World', selftext='') # throws APIException |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment