Guest User

Subreddit Stream

a guest
Aug 16th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import praw
  4. import time
  5.  
  6. client_id = "XXXXXXXX"
  7. client_secret = "XXXXXXXX"
  8. username = "XXXXXXXX"
  9. password = "XXXXXXXX"
  10. user_agent = 'XXXXXXXX by /u/XXXXXXXX',
  11.  
  12. def main():
  13.     reddit = praw.Reddit(
  14.         client_id=client_id,
  15.         client_secret=client_secret,
  16.         password=password,
  17.         username=username,
  18.         user_agent=user_agent,
  19.         )
  20.  
  21.     started_at = time.time()
  22.     print ">> Starting at %s" % started_at
  23.     for comment in reddit.subreddit('AskReddit').stream.comments():
  24.         if comment.created_utc > started_at:
  25.             print(">> New comment %s [%s] on parent %s (preview: %s...)"
  26.                 % (comment.id, comment.created_utc,
  27.                     comment.parent_id, comment.body[:20]))
  28.         else :
  29.             print(">> Ignoring historical comment %s [%s]"
  30.                 % (comment.id,
  31.                     comment.created_utc))
  32.  
  33. if __name__ == '__main__':
  34.     main()
Add Comment
Please, Sign In to add comment