Skip to content

Instantly share code, notes, and snippets.

@quasarj
Created April 19, 2018 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save quasarj/3b3f9685f2411fdb1488dca7abe34a57 to your computer and use it in GitHub Desktop.
Save quasarj/3b3f9685f2411fdb1488dca7abe34a57 to your computer and use it in GitHub Desktop.
reddit reply bot
import praw
SUBREDDIT_NAME = 'requestabot'
KEYWORD_RESPONSE_MAP = {
'hunter2': 'All I see is *******',
'lizard': 'There is a lizard in here!',
}
USERNAME = ''
PASSWORD = ''
CLIENT_ID = ''
CLIENT_SECRET = ''
USER_AGENT = 'script:reply to keywords in titless:v0.2:written by /u/doug89'
print("Authenticating...")
reddit = praw.Reddit(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
password=PASSWORD,
user_agent=USER_AGENT,
username=USERNAME)
print("Authenticaed as {}".format(reddit.user.me()))
print('Starting submission stream...')
for post in reddit.subreddit(SUBREDDIT_NAME).stream.submissions():
if post.saved:
# skip if this post is saved (meaning we have already processed it?)
continue
if post.author == reddit.user.me():
# skip if the post was made by us
continue
for keyword, response in KEYWORD_RESPONSE_MAP.items():
if keyword.lower() in post.title.lower():
post.save()
reply = post.reply(response)
print('http://reddit.com{}'.format(reply.permalink()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment