Advertisement
Guest User

Untitled

a guest
Jul 31st, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import os
  5. import requests
  6.  
  7. def bot_login():
  8.     print "Loggin in..."
  9.     r = praw.Reddit(username = config.username,
  10.             password = config.password,
  11.             client_id = config.client_id,
  12.             client_secret = config.client_secret,
  13.             user_agent = "phylohelper v0.1")
  14.     print "Logged in!"
  15.  
  16.     return r
  17.  
  18. def run_bot(r, comments_replied_to):
  19.     print "Obtaining 10 comments..."
  20.  
  21.     for comment in r.subreddit('whatsthissnaketest').comments(limit=10):
  22.         if comment.author = r.get_redditor('Phylogenizer') and if "*Lachesis muta*" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
  23.             print "String with \"*Lachesis muta*\" found in comment " + comment.id
  24.  
  25.             comment_reply = "This snake *Lachesis muta*, or the mute rattlesnake, is a venomous pit viper native to much of south America"
  26.  
  27.             comment.reply(comment_reply)
  28.             print "Replied to comment " + comment.id
  29.  
  30.             comments_replied_to.append(comment.id)
  31.  
  32.             with open ("comments_replied_to.txt", "a") as f:
  33.                 f.write(comment.id + "\n")
  34.  
  35.     print "Sleeping for 10 seconds..."
  36.     #Sleep for 10 seconds...
  37.     time.sleep(10)
  38.  
  39. def get_saved_comments():
  40.     if not os.path.isfile("comments_replied_to.txt"):
  41.         comments_replied_to = []
  42.     else:
  43.         with open("comments_replied_to.txt", "r") as f:
  44.             comments_replied_to = f.read()
  45.             comments_replied_to = comments_replied_to.split("\n")
  46.             comments_replied_to = filter(None, comments_replied_to)
  47.  
  48.     return comments_replied_to
  49.  
  50. r = bot_login()
  51. comments_replied_to = get_saved_comments()
  52. print comments_replied_to
  53.  
  54. while True:
  55.     run_bot(r, comments_replied_to)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement