Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. import praw
  2. import config
  3. import time
  4. import os
  5.  
  6. def bot_login():
  7. print("Loggin 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 = "busterronitest's dog --help comment responder v0.1")
  13. print("Logged in!")
  14.  
  15. return r
  16.  
  17. def run_bot(r, comments_replied_to):
  18. print("Obtaining 25 comments...")
  19.  
  20. for comment in r.subreddit('testingground4bots').comments(limit=10):
  21.  
  22. if "What is a dog?" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
  23. comment.reply("Dogs are small mammals. ")
  24. print ("Replied to comment " + comment.id)
  25.  
  26. # comments_replied_to.append(comment.id)
  27. comments_replied_to = list(filter(None, comments_replied_to))
  28.  
  29. with open ("comments_replied_to.txt", "a") as f:
  30. f.write(comment.id + "n")
  31.  
  32. print ("Sleeping for 10 seconds...")
  33. #Sleep for 10 seconds...
  34. time.sleep(10)
  35.  
  36. def get_saved_comments():
  37. if not os.path.isfile("comments_replied_to.txt"):
  38. comments_replied_to = []
  39. else:
  40. with open("comments_replied_to.txt", "r") as f:
  41. comments_replied_to = f.read()
  42. comments_replied_to = comments_replied_to.split("n")
  43. comments_replied_to = filter(None, comments_replied_to)
  44.  
  45. return comments_replied_to
  46.  
  47. r = bot_login()
  48. comments_replied_to = get_saved_comments()
  49. print (comments_replied_to)
  50.  
  51. count = 0
  52. while (count < 9):
  53. print ('The count is:', count)
  54. count = count + 1
  55. run_bot(r, comments_replied_to)
  56.  
  57. print("Good bye!")
  58.  
  59. Loggin in...
  60. Logged in!
  61. <filter object at 0x7fc15a37f4a8>
  62. The count is: 0
  63. Obtaining 25 comments...
  64. Sleeping for 10 seconds...
  65. The count is: 1
  66. Obtaining 25 comments...
  67. Sleeping for 10 seconds...
  68. The count is: 2
  69. Obtaining 25 comments...
  70. Replied to comment do9htf1
  71. Sleeping for 10 seconds...
  72. The count is: 3
  73. Obtaining 25 comments...
  74. Replied to comment do9htf1
  75. Sleeping for 10 seconds...
  76. The count is: 4
  77. Obtaining 25 comments...
  78. Replied to comment do9htf1
  79. Sleeping for 10 seconds...
  80. The count is: 5
  81. Obtaining 25 comments...
  82. Replied to comment do9htf1
  83. Sleeping for 10 seconds...
  84. The count is: 6
  85. Obtaining 25 comments...
  86. Replied to comment do9htf1
  87. Sleeping for 10 seconds...
  88. The count is: 7
  89. Obtaining 25 comments...
  90. Sleeping for 10 seconds...
  91. The count is: 8
  92. Obtaining 25 comments...
  93. Replied to comment do9htf1
  94. Sleeping for 10 seconds...
  95. Good bye!
  96.  
  97. filter(None, comments_replied_to)
  98.  
  99. list(filter(None, comments_replied_to))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement