Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.51 KB | None | 0 0
  1. import praw
  2. import time
  3. import os
  4. import config2
  5.  
  6.  
  7. def bot_login():
  8.     print("Logging in...")
  9.     r = praw.Reddit(username = config2.username,
  10.             password = config2.password,
  11.             client_id = config2.client_id,
  12.             client_secret = config2.client_secret,
  13.             user_agent = "Feel_Good_Bots feel good comment responder v0.1")
  14.     print("Logged in")
  15.  
  16.     return r
  17.  
  18.  
  19. keywords = ["im sad", "Im sad", "I don't feel good", "I feel bad"]
  20.  
  21.  
  22. def run_bot(r):
  23.     print("Obtaining 1000 comments!")
  24.     for comment in r.subreddit("all").comment(limit=1000):
  25.         if keywords in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
  26.             print("Keywords found!")
  27.             comment.reply("Hey! Feel better <3")
  28.             print("Replied to comments, " + comment.id)
  29.  
  30.             with open("comments_replied_to.txt", "a") as f:
  31.                 f.write(comment.id + "\n")
  32.  
  33.  
  34.     print("Sleep for 10 seconds...")
  35.     time.sleep(10)
  36.  
  37. def get_saved_comments():
  38.     if not os.path.isfile("comments_replied_to.txt"):
  39.         comments_replied_to = []
  40.     else:
  41.         with open("comments_replied_to.txt", "r") as f:
  42.             comments_replied_to = f.read()
  43.             comments_replied_to = comments_replied_to.split("\n")
  44.             comments_replied_to = filter(None, comments_replied_to)
  45.     return comments_replied_to
  46.  
  47.  
  48. r = bot_login()
  49. comments_replied_to = get_saved_comments()
  50. print(comments_replied_to)
  51.  
  52.  
  53. while True:
  54.     run_bot(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement