Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import config
- import random
- import os
- import time
- def bot_login():
- print "Logging in..."
- r = praw.Reddit(username = config.username,
- password = config.password,
- client_id = config.client_id,
- client_secret = config.client_secret,
- user_agent = "kemonomimi bot v0.1")
- print "Logged in!"
- return r
- def run_bot(r, comments_replied_to, catgirls):
- print catgirls
- print "Obtaining 25 comments..."
- for comment in r.subreddit('KemonomimiCheerUpBot').comments(limit=25):
- if ("Im sad" in comment.body and comment.id not in comments_replied_to
- and comment.author != r.user.me()):
- comment.reply("[Here](" + random.choice(catgirls) + ") is a"
- "picture of a catgirl! Hopefully this will cheer you"
- "up!"
- "\n\n"
- "---"
- "\n\n"
- "I am a bot. For more info on me and how to use me,"
- "see r/KemonomimiCheerUpBot")
- comments_replied_to.append(comment.id)
- with open("comments_replied_to.txt", "a") as f:
- f.write(comment.id + "\n")
- time.sleep(10)
- # Load catgirls from a file (defaults to catgirls.txt)
- def get_catgirls(fname='catgirls.txt'):
- if not os.path.isfile(fname):
- raise FileNotFoundError("Can't get catgirls from " + fname)
- catgirls = []
- with open(fname) as catgirls_file:
- catgirls_contents = catgirls_file.read()
- catgirls = catgirls_contents.split("\n")
- catgirls = filter(None, catgirls)
- catgirls = [catgirl.strip() for catgirl in catgirls]
- return catgirls
- 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
- if __name__ == '__main__':
- r = bot_login()
- catgirls = get_catgirls()
- comments_replied_to = get_saved_comments()
- while True:
- run_bot(r, comments_replied_to, catgirls)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement