Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import json
  2. import time
  3.  
  4. cmt = open('export.json').read()
  5. cmt = json.loads(cmt)
  6.  
  7. print(len(cmt['comments']))
  8. blk = set((
  9. '=======',
  10. '~~~~~~~~~~~~'
  11. ))
  12.  
  13. articles = {}
  14.  
  15. for cmt in cmt['comments']:
  16. ctime = int(time.mktime(time.strptime(cmt['ctime'], '%Y-%m-%d %H:%M:%S')) * 1000)
  17. remove = False
  18. for b in blk:
  19. if b in cmt['content']:
  20. remove = True
  21. break
  22. if remove:
  23. continue
  24.  
  25. if cmt['topicSourceId'] not in articles:
  26. url = cmt['topicUrl']
  27. articles[cmt['topicSourceId']] = {
  28. "title": cmt['topicTitle'],
  29. "url": url,
  30. "ttime": ctime, # use cmt time as ttime
  31. "sourceid": cmt['topicSourceId'],
  32. "comments": [],
  33. }
  34. articles[cmt['topicSourceId']]['comments'].append({
  35. "cmtid": cmt['id'],
  36. "ctime": ctime,
  37. "content": cmt['content'],
  38. "replyid": cmt['replyId'],
  39. "user": {
  40. "userid": cmt['referUserId'],
  41. "nickname": cmt['nickname'],
  42. "usericon": cmt['iconUrl'],
  43. "userurl": cmt['userProfileUrl'],
  44. },
  45. "ip": cmt['ip'],
  46. "channeltype": "1",
  47. "spcount": cmt['sp'] if 'sp' in cmt else '0',
  48. "opcount": cmt['op'] if 'op' in cmt else '0',
  49. "attachment": [] if not cmt['attachs'] else cmt['attachs'],
  50. })
  51.  
  52. with open('import.json', 'wb') as f:
  53. for a in articles:
  54. f.write(json.dumps(articles[a]))
  55. f.write('\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement