Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import re
- with open("FaceDeer.json") as data:
- jsondata = json.load(data)
- with open("reddit archive data.txt") as newerdata:
- newerjsondata = json.load(newerdata)
- fullcomments = dict()
- for key, comment in newerjsondata.items():
- comdict = dict()
- comdict['id'] = comment['id']
- comdict['link_url'] = comment['link']
- comdict['body'] = comment['body']
- comdict['created'] = int(comment['created'])
- comdict['link_title'] = comment['link_title']
- comdict['subreddit'] = comment['subreddit']
- comdict['link_id'] = None
- comdict['author'] = None
- comdict['fromBigQuery'] = False
- fullcomments[comment['id']] = comdict
- for comment in jsondata:
- if comment['id'] in fullcomments:
- fullcomments[comment['id']]['link_id'] = comment['link_id']
- fullcomments[comment['id']]['author'] = comment['author']
- else:
- link = "http://reddit.com/r/" + comment['subreddit'] + "/comments/" + re.sub('t[0-9]_','', comment['link_id']) + "/c/" + comment['id']
- comdict = dict()
- comdict['id'] = comment['id']
- comdict['link_url'] = link
- comdict['body'] = comment['body']
- comdict['created'] = int(comment['created_utc'])
- comdict['link_title'] = None
- comdict['subreddit'] = comment['subreddit']
- comdict['link_id'] = comment['link_id']
- comdict['author'] = comment['author']
- comdict['fromBigQuery'] = True
- fullcomments[comment['id']] = comdict
- ##with open("combined archive.txt", "w") as outfile:
- ## json.dump(fullcomments, outfile)
- commentlist = list(fullcomments.values())
- result = sorted(commentlist, key= lambda comment: comment['created'])
- print(result[0])
- with open("sorted archive.txt", "w") as outfile:
- json.dump(result, outfile)
Add Comment
Please, Sign In to add comment