Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.41 KB | None | 0 0
  1. import praw #you probably know what this is
  2. import base64 #encoded passwords
  3. from urllib.request import quote #to turn the parent comment into a link
  4. r = praw.Reddit(user_agent='GloriousGeorge (by /u/USERNAME)',
  5.                          client_id='', client_secret="",
  6.                          username='', password=base64.b64decode(b"").decode("utf-8", "ignore"))
  7. r.read_only = False #no idea if this is required. Kept it to be safe.
  8. subreddit = r.subreddit("pcmasterrace") #get the subreddit. "all" for all comments
  9. f = open("C:\\repliedto.txt", "r+") #REPLACE THE PATH
  10.  
  11.    
  12.  
  13. comments = subreddit.stream.comments() # get the comment stream
  14. x = 1 #for the counter
  15. for comment in comments: #for each comment in the comments stream. the current comment being processed is called "comment"
  16.     print("found new comment! processing... (" + str(x) + ")") #the str(x) thing is printing the number of the comment being proccesed
  17.     x += 1 #add 1 to the number
  18.     try:
  19.         text = str(comment.body) # Fetch body
  20.     except:
  21.         print("Failed to fetch or str body")
  22.     try:
  23.         author = str(comment.author) # Fetch author
  24.     except AttributeError: #check if the author has been deleted
  25.         print("Author has been deleted")
  26.         #author was deleted
  27.         continue
  28.     if author.lower() == "".lower(): #Don't reply to yourself
  29.         #myself
  30.         print("Comment is by myself")
  31.         continue
  32.  
  33.     if "/u/gloriousgeorge" in text: #check to see the comment is "!lmgtfy". use if text.lower() == "!lmgtfy".lower() to be non-case sensitive, use if "!lmgtfy" in text if you want the comment to be anywhere
  34.         if comment.id in f.read(): #if the comment is already in the file, bot has replied to it
  35.             print("ALREADY IN FILE")
  36.         if comment.id not in f.read(): #^
  37.             # Generate a message
  38.             print("Attempting Answer")
  39.             #quote() url-ifies the text, self explanatory i hope
  40.             try:
  41.                 comment.reply("It looks like you are trying to summon /u/GloriousGe0rge. \n\n_____\n\n^by ^/u/Shrellex") #reply to comment
  42.  
  43.             except praw.exceptions.APIException:
  44.                 print('RATELIMIT ERROR')
  45.             print("Replied to comment by " + author)
  46.             f.write(comment.id + "\n")#write comment id to file so it doesn't reply to it again
  47.             if comment.id in f.read():
  48.                 print("Written Successfully!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement