Advertisement
dmesticg

Untitled

Jun 12th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import os
  5. import random
  6. import re
  7.  
  8. def bot_login():
  9. print "Loggin in..."
  10. r = praw.Reddit(username = config.username,
  11. password = config.password,
  12. client_id = config.client_id,
  13. client_secret = config.client_secret,
  14. user_agent = "busterronitest's dog comment responder v0.1")
  15. print "Logged in!"
  16.  
  17. return r
  18.  
  19. def run_bot(r, comments_replied_to):
  20. print "Obtaining 25 comments..."
  21.  
  22. for comment in r.subreddit('clearbot').comments(limit=10):
  23. if "!winlose" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
  24. print "String with \"!winlose\" found in comment " + comment.id
  25. thecomment = comment.body
  26. betSize = int(re.match(r"!bet \((\d+)\)", thecomment).group(1))
  27. winlose = random.randint(1,100)
  28. if winlose < 50:
  29. win = "Win"
  30. else:
  31. win = "Lose"
  32. comment.reply("You {} {}".format(win, betSize))
  33. print "Replied to comment " + comment.id
  34.  
  35. comments_replied_to.append(comment.id)
  36.  
  37. with open ("comments_replied_to.txt", "a") as a:
  38. a.write(comment.id + "\n")
  39.  
  40. print "Sleeping for 10 seconds..."
  41. time.sleep(10)
  42.  
  43. def get_saved_comments():
  44. if not os.path.isfile("comments_replied_to.txt"):
  45. comments_replied_to = []
  46. else:
  47. with open("comments_replied_to.txt", "r") as f:
  48. comments_replied_to = f.read()
  49. comments_replied_to = comments_replied_to.split("\n")
  50. comments_replied_to = filter(None, comments_replied_to)
  51.  
  52. return comments_replied_to
  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