Skip to content

Instantly share code, notes, and snippets.

@gavin19
Created October 4, 2018 19:37
Show Gist options
  • Save gavin19/faa6bf52248a396414fa54364ad74ea0 to your computer and use it in GitHub Desktop.
Save gavin19/faa6bf52248a396414fa54364ad74ea0 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment