Advertisement
Guest User

Untitled

a guest
Apr 7th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. import praw
  2. import pdb
  3. import re
  4. import os
  5.  
  6.  
  7.  
  8. reddit=praw.Reddit(client_id='',
  9. client_secret='',
  10. username='',
  11. password='',
  12. user_agent='')
  13.  
  14. if not os.path.isfile("posts_replie_to.txt"):
  15. posts_replie_to = []
  16. else:
  17. with open("posts_replie_to.txt", "r") as f:
  18. posts_replie_to = f.read()
  19. posts_replie_to = posts_replie_to.split("\n")
  20. posts_replie_to = list(filter(None, posts_replie_to))
  21.  
  22. if not os.path.isfile("posts_repli_to.txt"):
  23. posts_repli_to = []
  24. else:
  25. with open("posts_repli_to.txt", "r") as f:
  26. posts_repli_to = f.read()
  27. posts_repli_to = posts_repli_to.split("\n")
  28. posts_repli_to = list(filter(None, posts_repli_to))
  29.  
  30. subreddit = reddit.subreddit('subreddit you like')
  31. comments = subreddit.stream.comments()
  32. for comment in comments:
  33. author=comment.author
  34. if comment.id not in posts_replie_to:
  35. posts_replie_to.append(comment.id)
  36. with open("posts_replie_to.txt", "w") as f:
  37. for comment_id in posts_replie_to:
  38. f.write(comment_id + "\n")
  39.  
  40. #if you want the bot to trigger on more words copy this below and put in a new word
  41. if re.search("fill in word if it finds the word it replies.", comment.body, re.IGNORECASE):
  42.  
  43. if author.name in posts_repli_to:
  44. print "you have already commented on %s" % comment.author
  45.  
  46.  
  47. if author.name not in posts_repli_to:
  48. print("Bot replying to : ", comment.body)
  49. posts_repli_to.append(author.name)
  50. message=("Hello /u/%s! I'm a bot. Bleepy bloop. ") % author.name
  51. comment.reply(message)
  52. with open("posts_repli_to.txt", "w") as f:
  53. for author.name in posts_repli_to:
  54. f.write(author.name + "\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement