Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import config
- import time
- import os
- def bot_login():
- print("Loggin in...")
- r = praw.Reddit(username = config.username,
- password = config.password,
- client_id = config.client_id,
- client_secret = config.client_secret,
- user_agent = "busterronitest's dog --help comment responder v0.1")
- print("Logged in!")
- return r
- def run_bot(r, comments_replied_to):
- print("Obtaining 25 comments...")
- for comment in r.subreddit('testingground4bots').comments(limit=10):
- if "What is a dog?" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
- comment.reply("Dogs are small mammals. ")
- print ("Replied to comment " + comment.id)
- # comments_replied_to.append(comment.id)
- comments_replied_to = list(filter(None, comments_replied_to))
- with open ("comments_replied_to.txt", "a") as f:
- f.write(comment.id + "n")
- print ("Sleeping for 10 seconds...")
- #Sleep for 10 seconds...
- time.sleep(10)
- def get_saved_comments():
- if not os.path.isfile("comments_replied_to.txt"):
- comments_replied_to = []
- else:
- with open("comments_replied_to.txt", "r") as f:
- comments_replied_to = f.read()
- comments_replied_to = comments_replied_to.split("n")
- comments_replied_to = filter(None, comments_replied_to)
- return comments_replied_to
- r = bot_login()
- comments_replied_to = get_saved_comments()
- print (comments_replied_to)
- count = 0
- while (count < 9):
- print ('The count is:', count)
- count = count + 1
- run_bot(r, comments_replied_to)
- print("Good bye!")
- Loggin in...
- Logged in!
- <filter object at 0x7fc15a37f4a8>
- The count is: 0
- Obtaining 25 comments...
- Sleeping for 10 seconds...
- The count is: 1
- Obtaining 25 comments...
- Sleeping for 10 seconds...
- The count is: 2
- Obtaining 25 comments...
- Replied to comment do9htf1
- Sleeping for 10 seconds...
- The count is: 3
- Obtaining 25 comments...
- Replied to comment do9htf1
- Sleeping for 10 seconds...
- The count is: 4
- Obtaining 25 comments...
- Replied to comment do9htf1
- Sleeping for 10 seconds...
- The count is: 5
- Obtaining 25 comments...
- Replied to comment do9htf1
- Sleeping for 10 seconds...
- The count is: 6
- Obtaining 25 comments...
- Replied to comment do9htf1
- Sleeping for 10 seconds...
- The count is: 7
- Obtaining 25 comments...
- Sleeping for 10 seconds...
- The count is: 8
- Obtaining 25 comments...
- Replied to comment do9htf1
- Sleeping for 10 seconds...
- Good bye!
- filter(None, comments_replied_to)
- list(filter(None, comments_replied_to))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement