Skip to content

Instantly share code, notes, and snippets.

@bboe
Last active February 17, 2021 00:24
Show Gist options
  • Save bboe/5e023c4e8f8c5990453c3baf896c856c to your computer and use it in GitHub Desktop.
Save bboe/5e023c4e8f8c5990453c3baf896c856c to your computer and use it in GitHub Desktop.
BBoe's Updates to "How To Make A reddit Bot — Part One"
Intro:
I'm Bryce (/u/bboe) Author of PRAW
/u/busterroni's Submission:
https://www.reddit.com/r/learnpython/comments/5ury27/heres_a_tutorial_i_made_on_creating_a_reddit_bot/
/u/busterroni's Part 1:
https://www.youtube.com/watch?v=krTUf7BpTc0
Tasks
-----
1) Convert for python 3.6 (done)
2) Use `reddit` instead of `r` (done)
3) Use main function (done)
4) Change `bot_login` to `authenticate` (done)
5) Use praw.ini (done)
6) Address flake8 issues
# Note: these credentials were revoked before being made public
[dogbot]
client_id: EBhviLF4IW1LQA
client_secret: dEoavAgJ5OO-eHLBwemY4Z7y3m8
password: notarealpassword
username: pyapitestuser2
# copyright (c) busterroni February 18, 2017
# video: https://www.youtube.com/watch?v=krTUf7BpTc0
# Updates by Bryce Boe (/u/bboe)
import praw
import time
REPLY_MESSAGE = ("I also love dogs! [Here](http://i.imgur.com/LLgRKeq.jpg) is "
"an image of one!")
def authenticate():
print("Authenticating...")
reddit = praw.Reddit(
'dogbot',
user_agent="busterronitest's dog comment responder v0.1")
print("Authenticated as {}".format(reddit.user.me()))
return reddit
def main():
reddit = authenticate()
while True:
run_bot(reddit)
def run_bot(reddit):
print("Obtaining 25 comments...")
for comment in reddit.subreddit('test').comments(limit=25):
if "dog" in comment.body:
print('String with "dog" found in comment {}'.format(comment.id))
comment.reply(REPLY_MESSAGE)
print("Replied to comment " + comment.id)
print("Sleeping for 10 seconds...")
# Sleep for 10 seconds...
time.sleep(10)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment