Advertisement
doug89

Untitled

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