Skip to content

Instantly share code, notes, and snippets.

@gavin19
Created February 6, 2020 19:55
Show Gist options
  • Save gavin19/42d4af576fcd3ff707182d85493f4055 to your computer and use it in GitHub Desktop.
Save gavin19/42d4af576fcd3ff707182d85493f4055 to your computer and use it in GitHub Desktop.
import praw
userAgent = 'xxx'
cID = 'xxx'
cSC= 'xxx'
userN = 'xxx'
userP ='xxx'
numFound = 0
reddit = praw.Reddit(user_agent=userAgent,
client_id=cID,
client_secret=cSC,
username=userN,
password=userP)
subreddit = reddit.subreddit('xxx')
keywords = {
'phrase one': 'reply for phrase one',
'phrase two': 'reply for phrase two',
'phrase three': 'reply for phrase three',
'phrase four': 'reply for phrase four'
}
def match_phrase(kw, cmt):
if kw in cmt:
return True
return False
for comment in subreddit.stream.comments(skip_existing=True):
cmt = comment.body.lower()
for kw in keywords:
if match_phrase(kw, cmt):
print("---------------------------------")
print("Found: " + kw)
print('Bot saying: ', keywords[kw])
comment.reply(keywords[kw])
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment