generate-emoji-picker.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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-{0}" title="{1}" aria-label="{1} Emoji">'.format(i, category['name']))
  27. print(' <img src="emoji/{0}.svg" class="em-{0}" height="24" width="24" role="button" tabindex="0"></span>'.format(category['id']))
  28. print(' </label>')
  29. print(' <div class="content" role="listbox">')
  30. for emoji in groups[category['id']]:
  31. if emoji['representation'] == 'emoji-default':
  32. hex_codepoint = emoji['codepoint'].lower()
  33. else:
  34. hex_codepoint = emoji['codepoint_fully_qualified']
  35. print(' <span class="em em-{3}-{0}" role="option" tabindex="0" data-c="{0}" data-s="{1}" title="{2}">{4}</span>'.format(
  36. emoji['codepoint'].lower(),
  37. emoji['shortname'],
  38. emoji['name'],
  39. category['id'],
  40. make_hexchar(hex_codepoint),
  41. ))
  42. print(' </div>')
  43. print(' </div>')
  44. print('</div>')