Guest User

Untitled

a guest
Apr 15th, 2018
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. import praw
  2. import os
  3.  
  4. r = praw.Reddit(username='username', password='password', client_id='app_id', client_secret='app_secret', user_agent='comment notifier for cuddlefishcat')
  5.  
  6. if not os.path.isfile("commentsRead.txt"):
  7. commentsRead = []
  8. else:
  9. with open("commentsRead.txt", "r") as f:
  10. commentsRead = f.read()
  11. commentsRead = commentsRead.split("\n")
  12. commentsRead = list(filter(None, commentsRead))
  13.  
  14. subreddits = ['subreddit1', 'subreddit2']
  15.  
  16. for subreddit in subreddits:
  17. for comment in r.subreddit(subreddit).comments(limit=10):
  18. if comment.id not in commentsRead:
  19. print 'sent comment ' + comment.permalink
  20. r.redditor('targetuser').message('New comment in ' + subreddit, ' here\'s the text:\n\n' + comment.body + '\n\n' + comment.permalink)
  21. commentsRead.append(comment.id)
  22.  
  23. with open("commentsRead.txt", "w") as f:
  24. for post_id in commentsRead:
  25. f.write(post_id + "\n")
Add Comment
Please, Sign In to add comment