Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import time
- import os
- import config2
- def bot_login():
- print("Logging in...")
- r = praw.Reddit(username = config2.username,
- password = config2.password,
- client_id = config2.client_id,
- client_secret = config2.client_secret,
- user_agent = "Feel_Good_Bots feel good comment responder v0.1")
- print("Logged in")
- return r
- keywords = ["im sad", "Im sad", "I don't feel good", "I feel bad"]
- def run_bot(r):
- print("Obtaining 1000 comments!")
- for comment in r.subreddit("all").comment(limit=1000):
- if keywords in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
- print("Keywords found!")
- comment.reply("Hey! Feel better <3")
- print("Replied to comments, " + comment.id)
- with open("comments_replied_to.txt", "a") as f:
- f.write(comment.id + "\n")
- print("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)
- while True:
- run_bot(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement