Guest User

PenceBot Changes

a guest
Oct 29th, 2016
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. import praw
  2. bot = praw.Reddit(user_agent='PencePlane',
  3.                    client_id='[REDACTED]',
  4.                    client_secret='[REDACTED]',
  5.                    username='PencePlane-Bot',
  6.                    password='[REDACTED]')
  7.  
  8. comments = bot.get_comments("the_donald", gilded_only=False)
  9.  
  10. searchStrings = ["pence plane", "no breaks"]
  11.  
  12. pencePlaneSpeed = 0
  13.  
  14. def bot():
  15.     While True:
  16.         try:
  17.             for comment in comments:
  18.                 text = comment.body
  19.                 author = comment.author
  20.                 if comment.author != "PencePlane-Bot" or "/u/PencePlane-Bot" or "u/PencePlaneBot":
  21.                     if any(string in text for string in searchStrings):
  22.                     # Generate a message
  23.                     pencePlaneSpeed = pencePlaneSpeed + 100
  24.                     message = "THE PENCE PLANE HAS NO BRAKES. Current Speed: %s mph. Post by Pence Plane Bot v.0.1. Bot by /u/njmksr." % pencePlaneSpeed
  25.                     comment.reply(message)
  26.  
  27.         # Allows the bot to exit on ^C, all other exceptions are ignored
  28.         except KeyboardInterrupt:
  29.             break
  30.         # Check to see if it Reddit Server Issue
  31.         except praw.errors.HTTPException as e:
  32.             exc = e._raw
  33.             print("Some thing bad happened! HTTPError", exc.status_code)
  34.             if exc.status_code == 503:
  35.                 print("Let's wait till reddit comes back! Sleeping 60 seconds.")
  36.                 time.sleep(60)
  37.             if exc.status_code == 403:
  38.                 print('Reddit is denying the bot access')
  39.                 time.sleep(300)
  40.         except Exception as e:
  41.             print('Something Broke')
  42.             time.sleep(300)
Add Comment
Please, Sign In to add comment