Skip to content

Instantly share code, notes, and snippets.

@PythonCoderAS
Last active September 21, 2017 17:15
Show Gist options
  • Select an option

  • Save PythonCoderAS/f2956909fac845453767d3313fae8323 to your computer and use it in GitHub Desktop.

Select an option

Save PythonCoderAS/f2956909fac845453767d3313fae8323 to your computer and use it in GitHub Desktop.
Easy way to delete posts by your bot
import praw
u = ''
p = ''
c_id = ''
c_secret = ''
reddit = praw.Reddit(username = u, password = p, client_id = c_id, cient_secret = c_secret)
def main():
try:
for item in reddit.inbox.stream():
try:
if 'delete' in item.body.lower():
item.parent().delete()
except:
pass
while True:
try:
main()
except(KeyboardInterrupt):
raise KeyboardInterrupt
@bjuergens
Copy link

def main 
    # ...
    except: 
        main()

This recursive call in the except-block gives me the chills. You should get rid of the inner try/except block, and just do all the exception handling on the outside.

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