Last active
February 17, 2021 00:24
-
-
Save bboe/5e023c4e8f8c5990453c3baf896c856c to your computer and use it in GitHub Desktop.
BBoe's Updates to "How To Make A reddit Bot — Part One"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: these credentials were revoked before being made public | |
[dogbot] | |
client_id: EBhviLF4IW1LQA | |
client_secret: dEoavAgJ5OO-eHLBwemY4Z7y3m8 | |
password: notarealpassword | |
username: pyapitestuser2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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