daily pastebin goal
67%
SHARE
TWEET

Untitled

a guest Apr 21st, 2018 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import praw
  2. import config
  3. import time
  4. import os
  5.  
  6. def bot_login():
  7.     print ("logging in...")
  8.     r = praw.Reddit(username = config.username,
  9.                 password = config.password,
  10.                 client_id = config.client_id,
  11.                 client_secret = config.client_secret,
  12.                 user_agent = "trashdogo's dog commenter v0.1")
  13.     print ("logged in!")
  14.  
  15.     return r
  16.  
  17. def run_bot(r, comments_replied_to):
  18.     print ("obtaining 25 comments...")
  19.  
  20.     for comment in r.subreddit('test').comments(limit=25):
  21.         if "dog" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
  22.             print ("string with \"dog\" found in comment!!" + comment.id)
  23.             comment.reply("Hey, I also love dogs")
  24.             print ("replied to comment ") and comment.id
  25.  
  26.             comments_replied_to.append(comment.id)
  27.  
  28.             with open ("comments_replied_to.txt", "a") as f:
  29.                 f.write(comment.id + "\n")
  30.  
  31.     print ("sleeping for 10 seconds")
  32.     time.sleep(10)
  33.  
  34. def get_saved_comments():
  35.     if not os.path.isfile("comments_replied_to.txt"):
  36.         comments_replied_to = []
  37.     else:
  38.         with open("comments_replied_to.txt", "r") as f:
  39.             comments_replied_to = f.read()
  40.             comments_replied_to = comments_replied_to.split("\n")
  41.             comments_replied_to = filter(None, comments_replied_to)
  42.  
  43.     return comments_replied_to
  44.  
  45. r = bot_login()
  46. comments_replied_to = get_saved_comments()
  47. print (comments_replied_to)
  48.  
  49. while True:
  50.     run_bot(r, comments_replied_to)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top