Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw # Python Reddit API Wrapper
- import re # Allows search function
- import os # Allows the bot to create a text file to store comments that it's checked
- import time # Allows the sleep function
- # Log in to Reddit
- reddit = praw.Reddit(client_id='CLIENT_ID_GOES_HERE',
- client_secret="CLIENT_SECRET_GOES_HERE", password='PASSWORD_GOES_HERE',
- user_agent='USER_AGENT_GOES_HERE', username='USERNAME_GOES_HERE')
- print "Logged in bois"
- time.sleep(1) # Cleans up the output
- while 1+1==2: #Creates a loop so that the bot is always checking for new comments
- # Create and maintain a file to store posts already replied to, ensuring the bot doesn't double-reply
- if not os.path.isfile("commentsChecked.txt"):
- commentsChecked=[]
- else:
- with open("commentsChecked.txt", "r") as f:
- commentsChecked = f.read()
- commentsChecked = commentsChecked.split("\n")
- commentsChecked = list(filter(None, commentsChecked))
- # The actual function of the bot
- subreddit = reddit.subreddit('teenagers')
- for submission in reddit.subreddit('teenagers').new(limit=25):
- comments = submission.comments.list()
- submission.comments.replace_more(limit=None)
- for comment in submission.comments:
- 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
- print "%s said something!" % comment.author # The %s and % allow the comment author's username to show in the output
- print "'%s'" % comment.body
- commentsChecked.append(comment.id) # Adds the comment ID to the list of comments that have been checked
- time.sleep(20) # Prevents the bot from being banned for excessively refreshing
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement