FaceDeer

Script for archiving recent Reddit posts

Jun 13th, 2016
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. import praw
  2. import json
  3.  
  4.  
  5. reddit = praw.Reddit(user_agent="quickie comment archiver")
  6. reddit.login("FaceDeer", "******NOPEYOUDONTGETMYPASSWORDSORRY******", disable_warning=True)
  7.  
  8. user = reddit.get_redditor("FaceDeer")
  9.  
  10. #sort='new'
  11. #sort='top'
  12. #sort='hot'
  13. #sort='controversial'
  14. comments = user.get_comments(sort="new",limit=1000)
  15.  
  16. outputdict = dict()
  17. try:
  18.     with open('combined archive.txt', 'r') as infile:
  19.         outputdict = json.load(infile)
  20. except FileNotFoundError:
  21.     pass
  22.  
  23. counter = 0
  24.  
  25. try:
  26.     for com in comments:
  27.         counter = counter + 1
  28.         if com.id not in outputdict:
  29.             comdict = dict()
  30.             comdict['id'] = com.id
  31.             comdict['link'] = com.permalink
  32.             comdict['body'] = com.body
  33.             comdict['created'] = com.created
  34.             comdict['link_title'] = com.link_title
  35.             comdict['subreddit'] = com.subreddit._fast_name
  36.             comdict['link_url'] = com.permalink
  37.             comdict['author'] = 'FaceDeer'
  38.             comdict['link_id'] = com.link_id
  39.             comdict['fromBigQuery'] = False
  40.             outputdict[com.id] = comdict
  41.             print('%d: "%s" in r/%s' % (counter, comdict['link_title'], comdict['subreddit']))
  42.         else:
  43.             print('%d: %s is already in the archive' % (counter, com.id))
  44.             break
  45.  
  46. finally:
  47.     with open('combined archive.txt', 'w') as outfile:
  48.         json.dump(outputdict, outfile, indent=1, sort_keys=True)
Add Comment
Please, Sign In to add comment