Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.77 KB | None | 0 0
  1. import praw # Python Reddit API Wrapper
  2. import re # Allows search function
  3. import os # Allows the bot to create a text file to store comments that it's checked
  4. import time # Allows the sleep function
  5.  
  6. # Log in to Reddit
  7. reddit = praw.Reddit(client_id='CLIENT_ID_GOES_HERE',
  8.                      client_secret="CLIENT_SECRET_GOES_HERE", password='PASSWORD_GOES_HERE',
  9.                      user_agent='USER_AGENT_GOES_HERE', username='USERNAME_GOES_HERE')
  10. print "Logged in bois"
  11.  
  12. time.sleep(1) # Cleans up the output
  13.  
  14. while 1+1==2: #Creates a loop so that the bot is always checking for new comments
  15.  
  16. # Create and maintain a file to store posts already replied to, ensuring the bot doesn't double-reply
  17.     if not os.path.isfile("commentsChecked.txt"):
  18.         commentsChecked=[]
  19.  
  20.     else:
  21.         with open("commentsChecked.txt", "r") as f:
  22.             commentsChecked = f.read()
  23.             commentsChecked = commentsChecked.split("\n")
  24.             commentsChecked = list(filter(None, commentsChecked))
  25.  
  26. # The actual function of the bot           
  27.             subreddit = reddit.subreddit('teenagers')
  28.             for submission in reddit.subreddit('teenagers').new(limit=25):
  29.             comments = submission.comments.list()
  30.             submission.comments.replace_more(limit=None)
  31.             for comment in submission.comments:
  32.                 if re.search("sodanazi", comment.body, re.IGNORECASE) or re.search("sodaman", comment.body, re.IGNORECASE) or re.search("soda doctor", comment.body, re.IGNORECASE): # Thanks timawesomeness
  33.                     print "%s said something!" % comment.author # The %s and % allow the comment author's username to show in the output
  34.                     print "'%s'" % comment.body
  35.                     commentsChecked.append(comment.id) # Adds the comment ID to the list of comments that have been checked
  36.                     time.sleep(20) # Prevents the bot from being banned for excessively refreshing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement