jsonutils.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import json
  2. import log
  3. def write_emoji(emoji, json_out):
  4. log.out('Converting to JSON...', indent=4)
  5. j = json.dumps(emoji, sort_keys=True, indent=4)
  6. log.out('Exporting to file: ' + json_out, indent=4)
  7. f = open(json_out, 'w')
  8. f.write(j)
  9. f.close()
  10. def write_web(emoji, web_out):
  11. cats = {}
  12. roots = {}
  13. out = {'cats': cats, 'roots': roots}
  14. log.out('Exporting metadata for MutStd website...', 36)
  15. log.out('Processing emoji...', indent=4)
  16. for e in emoji:
  17. if 'root' not in e:
  18. raise ValueError('no root defined for emoji: ' +str(e))
  19. if 'cat' not in e:
  20. raise ValueError('no category defined for emoji: ' + str(e))
  21. if e['cat'] not in cats:
  22. cats[e['cat']] = []
  23. if e['root'] not in cats[e['cat']]:
  24. cats[e['cat']].append(e['root'])
  25. roots[e['root']] = None
  26. if 'morph' in e or 'color' in e:
  27. morph = e.get('morph', '')
  28. color = e.get('color', '')
  29. suffix = morph + '_' + color if morph and color else morph + color
  30. if roots[e['root']] is None:
  31. roots[e['root']] = []
  32. roots[e['root']].append(suffix)
  33. log.out('Converting to JSON...', indent=4)
  34. j = json.dumps(out, sort_keys=True, indent=4)
  35. log.out('Exporting to file: ' + web_out, indent=4)
  36. f = open(web_out, 'w')
  37. f.write(j)
  38. f.close()