Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import json
- reddit = praw.Reddit(user_agent="quickie comment archiver")
- reddit.login("FaceDeer", "******NOPEYOUDONTGETMYPASSWORDSORRY******", disable_warning=True)
- user = reddit.get_redditor("FaceDeer")
- #sort='new'
- #sort='top'
- #sort='hot'
- #sort='controversial'
- comments = user.get_comments(sort="new",limit=1000)
- outputdict = dict()
- try:
- with open('combined archive.txt', 'r') as infile:
- outputdict = json.load(infile)
- except FileNotFoundError:
- pass
- counter = 0
- try:
- for com in comments:
- counter = counter + 1
- if com.id not in outputdict:
- comdict = dict()
- comdict['id'] = com.id
- comdict['link'] = com.permalink
- comdict['body'] = com.body
- comdict['created'] = com.created
- comdict['link_title'] = com.link_title
- comdict['subreddit'] = com.subreddit._fast_name
- comdict['link_url'] = com.permalink
- comdict['author'] = 'FaceDeer'
- comdict['link_id'] = com.link_id
- comdict['fromBigQuery'] = False
- outputdict[com.id] = comdict
- print('%d: "%s" in r/%s' % (counter, comdict['link_title'], comdict['subreddit']))
- else:
- print('%d: %s is already in the archive' % (counter, com.id))
- break
- finally:
- with open('combined archive.txt', 'w') as outfile:
- json.dump(outputdict, outfile, indent=1, sort_keys=True)
Add Comment
Please, Sign In to add comment