Advertisement
doug89

Untitled

Jul 7th, 2017
2,288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import praw
  2.  
  3. SUBREDDIT_NAME = 'requestabot'
  4. KEYWORDS = ['hunter2', 'lizard']
  5. RESPONSE = 'There is a keyword in your comment!'
  6.  
  7. USERNAME = ''
  8. PASSWORD = ''
  9. CLIENT_ID = ''
  10. CLIENT_SECRET = ''
  11.  
  12. USER_AGENT = 'script:reply to keywords in comments:v0.2:written by /u/doug89'
  13.  
  14. print("Authenticating...")
  15. reddit = praw.Reddit(
  16.     client_id=CLIENT_ID,
  17.     client_secret=CLIENT_SECRET,
  18.     password=PASSWORD,
  19.     user_agent=USER_AGENT,
  20.     username=USERNAME)
  21. print("Authenticaed as {}".format(reddit.user.me()))
  22.  
  23. print('Starting comment stream...')
  24. for comment in reddit.subreddit(SUBREDDIT_NAME).stream.comments():
  25.     if comment.saved:
  26.         continue
  27.     has_keyword = any(k.lower() in comment.body.lower() for k in KEYWORDS)
  28.     not_self = comment.author != reddit.user.me()
  29.     if has_keyword and not_self:
  30.         comment.save()
  31.         reply = comment.reply(RESPONSE)
  32.         print('http://reddit.com{}'.format(reply.permalink()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement