Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import os
  5. import random
  6. import re
  7. import requests
  8.  
  9. def bot_login():
  10. print ("Loggin in...")
  11. global r
  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 = config.user_agent)
  17. print ("Logged in!")
  18.  
  19. def run_bot():
  20. global r
  21. global comments_dealt_with
  22. for subreddit in config.subreddits:
  23. print ("Obtaining 25 comments in " + subreddit)
  24. for comment in r.subreddit(subreddit).comments(limit=25):
  25. if ("RemindMeBTC!" in comment.body and comment.id not in comments_dealt_with and comment.author != r.user.me()):
  26. print ("String with \"RemindMeBTC!\" found in comment " + comment.id)
  27. thecomment = comment.
  28. try:
  29. if "!RemindMeBTC" in thecomment:
  30. thecomment = thecomment.split(" ")
  31. price = thecomment[1]
  32. comment.reply("Alright, I'll send you a message when bitcoin hits " + price)
  33. with open ("need_to_.txt", "a") as a:
  34. a.write(comment.author + " " + price + "\n")
  35. comments_dealt_with.append(comment.id)
  36. with open ("comments_dealt_with.txt", "a") as a:
  37. a.write(comment.id + "\n")
  38. except (AttributeError, ValueError):
  39. print ("Invalid formatting, ignoring")
  40. comments_dealt_with.append(comment.id)
  41. with open ("comments_dealt_with.txt", "a") as a:
  42. a.write(comment.id + "\n")
  43. continue
  44.  
  45.  
  46. def get_saved_comments():
  47. global comments_dealt_with
  48. if not os.path.isfile("comments_dealt_with.txt"):
  49. comments_dealt_with = []
  50. else:
  51. with open("comments_dealt_with.txt", "r") as f:
  52. comments_dealt_with = f.read()
  53. comments_dealt_with = comments_dealt_with.split("\n")
  54. #comments_dealt_with = filter(None, comments_dealt_with)
  55.  
  56.  
  57. bot_login()
  58. get_saved_comments()
  59.  
  60. while True:
  61. run_bot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement