Guest User

Untitled

a guest
Oct 5th, 2018
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import os
  2. import re
  3. import praw
  4. import time
  5.  
  6. SKIP = ['tacobellscannon'] # users to skip replies to
  7. WORDS = ['aword', 'word2'] # words to match
  8. REPLY = "You said, '{0}'. Thanks." # template for replies
  9. LAUNCHED = time.time()
  10.  
  11.  
  12. def main():
  13. reddit = praw.Reddit(user_agent='/r/ouija replier',
  14. client_id='CLIENT_ID', client_secret='CLIENT_SECRET',
  15. username='USERNAME', password='PASSWORD')
  16. for cmt in reddit.subreddit('askouija').stream.comments():
  17. parse_comment(cmt)
  18.  
  19.  
  20. def skip_comment(cmt):
  21. # check if the OP is in the ignore list
  22. # or if the comment predates the launch of the script
  23. to_skip = [cmt.author in SKIP,
  24. cmt.created_utc < LAUNCHED]
  25. return any(to_skip)
  26.  
  27.  
  28. def parse_comment(cmt):
  29. if skip_comment(cmt):
  30. return # Skip comment
  31. for word in WORDS:
  32. # look for exact word match in comment, ignoring case
  33. if re.search(r'\b' + word + r'\b', cmt.body, re.IGNORECASE):
  34. cmt.reply(REPLY.format(word)) # reply to comment using our template
  35. break # break out of loop checking for words since we got a match
  36.  
  37.  
  38. if __name__ == '__main__':
  39. main()
Add Comment
Please, Sign In to add comment