Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  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 = "The Reddit Commenter v1.0")
  13. print("Logged in!")
  14.  
  15. return r
  16.  
  17. def run_bot(r, comments_replied_to):
  18. print("Searching last 1000 comments")
  19.  
  20. for comment in r.subreddit('registertovotebot').comments(limit=1000):
  21. if "register to vote" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
  22. print("String with register to vote found in comment") + comment.id
  23. comment.reply("Please visit")
  24. print("Replied to comment") + 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("Search Completed.")
  32.  
  33. print(comments_replied_to)
  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