Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import re
- import praw
- import time
- SKIP = ['tacobellscannon'] # users to skip replies to
- WORDS = ['aword', 'word2'] # words to match
- REPLY = "You said, '{0}'. Thanks." # template for replies
- LAUNCHED = time.time()
- def main():
- reddit = praw.Reddit(user_agent='/r/ouija replier',
- client_id='CLIENT_ID', client_secret='CLIENT_SECRET',
- username='USERNAME', password='PASSWORD')
- for cmt in reddit.subreddit('askouija').stream.comments():
- parse_comment(cmt)
- def skip_comment(cmt):
- # check if the OP is in the ignore list
- # or if the comment predates the launch of the script
- to_skip = [cmt.author in SKIP,
- cmt.created_utc < LAUNCHED]
- return any(to_skip)
- def parse_comment(cmt):
- if skip_comment(cmt):
- return # Skip comment
- for word in WORDS:
- # look for exact word match in comment, ignoring case
- if re.search(r'\b' + word + r'\b', cmt.body, re.IGNORECASE):
- cmt.reply(REPLY.format(word)) # reply to comment using our template
- break # break out of loop checking for words since we got a match
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment