generate-emoji-picker.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env python3
  2. import json
  3. GROUPS_JSON = '../../../twemoji-picker/generated/groups.json'
  4. # Load and group emoji data
  5. with open(GROUPS_JSON, 'r') as f:
  6. groups = json.loads(f.read())
  7. # Define category order
  8. category_order = [
  9. {'id': 'people', 'name': 'Smileys & People'},
  10. {'id': 'nature', 'name': 'Animals & Nature'},
  11. {'id': 'food', 'name': 'Food & Drink'},
  12. {'id': 'activity', 'name': 'Activity'},
  13. {'id': 'travel', 'name': 'Travel & Places'},
  14. {'id': 'objects', 'name': 'Objects'},
  15. {'id': 'symbols', 'name': 'Symbols'},
  16. {'id': 'flags', 'name': 'Flags'},
  17. ]
  18. # Helper functions
  19. def make_hexchar(codepoint):
  20. return '&#x%s;' % codepoint.replace('-', ';&#x')
  21. # Generate HTML
  22. print('<div class="twemoji-picker">')
  23. for i, category in enumerate(category_order):
  24. print(' <div class="tab">')
  25. print(' <input type="radio" id="tab-%d" name="tabs"%s>' % (i, ' checked' if i == 0 else ''))
  26. print(' <label for="tab-%d" title="%s">' % (i, category['name']))
  27. print(' <img src="/emoji/{0}.svg" class="em-{0}" height="24" width="24"></span>'.format(category['id']))
  28. print(' </label>')
  29. print(' <div class="content">')
  30. for emoji in groups[category['id']]:
  31. print(' <span class="em em-{3}-{0}" data-c="{0}" data-s="{1}" title="{2}">{4}</span>'.format(
  32. emoji['codepoint'].lower(),
  33. emoji['shortname'],
  34. emoji['name'],
  35. category['id'],
  36. make_hexchar(emoji['codepoint_fully_qualified']),
  37. ))
  38. print(' </div>')
  39. print(' </div>')
  40. print('</div>')