Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 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.  
  20.  
  21. def run_bot(r):
  22.     print("Obtaining 1000 comments!")
  23.     keywords = ["im sad", "Im sad", "I don't feel good", "I feel bad", "I wish i was dead"]
  24.  
  25.     for comment in r.subreddit('all').comments(limit=1000):
  26.         if keywords in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
  27.             print("Keywords found!")
  28.             comment.reply("Hey! Feel better <3")
  29.             print("Replied to comments, " + comment.id)
  30.  
  31.             with open("comments_replied_to.txt", "a") as f:
  32.                 f.write(comment.id + "\n")
  33.  
  34.  
  35.     print("Sleep for 10 seconds...")
  36.     time.sleep(10)
  37.  
  38. def get_saved_comments():
  39.     if not os.path.isfile("comments_replied_to.txt"):
  40.         comments_replied_to = []
  41.     else:
  42.         with open("comments_replied_to.txt", "r") as f:
  43.             comments_replied_to = f.read()
  44.             comments_replied_to = comments_replied_to.split("\n")
  45.             comments_replied_to = filter(None, comments_replied_to)
  46.     return comments_replied_to
  47.  
  48.  
  49. r = bot_login()
  50. comments_replied_to = get_saved_comments()
  51. print(comments_replied_to)
  52.  
  53.  
  54. while True:
  55.     run_bot(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement