Advertisement
Guest User

Untitled

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