Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- bot = praw.Reddit(user_agent='PencePlane',
- client_id='[REDACTED]',
- client_secret='[REDACTED]',
- username='PencePlane-Bot',
- password='[REDACTED]')
- comments = bot.get_comments("the_donald", gilded_only=False)
- searchStrings = ["pence plane", "no breaks"]
- pencePlaneSpeed = 0
- def bot():
- While True:
- try:
- for comment in comments:
- text = comment.body
- author = comment.author
- if comment.author != "PencePlane-Bot" or "/u/PencePlane-Bot" or "u/PencePlaneBot":
- if any(string in text for string in searchStrings):
- # Generate a message
- pencePlaneSpeed = pencePlaneSpeed + 100
- message = "THE PENCE PLANE HAS NO BRAKES. Current Speed: %s mph. Post by Pence Plane Bot v.0.1. Bot by /u/njmksr." % pencePlaneSpeed
- comment.reply(message)
- # Allows the bot to exit on ^C, all other exceptions are ignored
- except KeyboardInterrupt:
- break
- # Check to see if it Reddit Server Issue
- except praw.errors.HTTPException as e:
- exc = e._raw
- print("Some thing bad happened! HTTPError", exc.status_code)
- if exc.status_code == 503:
- print("Let's wait till reddit comes back! Sleeping 60 seconds.")
- time.sleep(60)
- if exc.status_code == 403:
- print('Reddit is denying the bot access')
- time.sleep(300)
- except Exception as e:
- print('Something Broke')
- time.sleep(300)
Add Comment
Please, Sign In to add comment