Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import time
- cmt = open('export.json').read()
- cmt = json.loads(cmt)
- print(len(cmt['comments']))
- blk = set((
- '=======',
- '~~~~~~~~~~~~'
- ))
- articles = {}
- for cmt in cmt['comments']:
- ctime = int(time.mktime(time.strptime(cmt['ctime'], '%Y-%m-%d %H:%M:%S')) * 1000)
- remove = False
- for b in blk:
- if b in cmt['content']:
- remove = True
- break
- if remove:
- continue
- if cmt['topicSourceId'] not in articles:
- url = cmt['topicUrl']
- articles[cmt['topicSourceId']] = {
- "title": cmt['topicTitle'],
- "url": url,
- "ttime": ctime, # use cmt time as ttime
- "sourceid": cmt['topicSourceId'],
- "comments": [],
- }
- articles[cmt['topicSourceId']]['comments'].append({
- "cmtid": cmt['id'],
- "ctime": ctime,
- "content": cmt['content'],
- "replyid": cmt['replyId'],
- "user": {
- "userid": cmt['referUserId'],
- "nickname": cmt['nickname'],
- "usericon": cmt['iconUrl'],
- "userurl": cmt['userProfileUrl'],
- },
- "ip": cmt['ip'],
- "channeltype": "1",
- "spcount": cmt['sp'] if 'sp' in cmt else '0',
- "opcount": cmt['op'] if 'op' in cmt else '0',
- "attachment": [] if not cmt['attachs'] else cmt['attachs'],
- })
- with open('import.json', 'wb') as f:
- for a in articles:
- f.write(json.dumps(articles[a]))
- f.write('\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement