generate-emoji-picker.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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" data-skintone="0">')
  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. def print_emoji(emoji):
  31. print(' ', end='')
  32. print('<span class="em em-{}-{}"'.format(category['id'], emoji['twemoji_codepoint'].lower()), end='')
  33. print(' role="option" tabindex="0"', end='')
  34. print(' data-c="{}"'.format(emoji['codepoint'].lower()), end='')
  35. print(' data-s="{}"'.format(emoji['shortname']), end='')
  36. if 'skins' in emoji:
  37. print(' data-t="0"', end='')
  38. if 'skintone' in emoji:
  39. print(' data-t="{}"'.format(emoji['skintone']), end='')
  40. print(' title="{}"'.format(emoji['name']), end='')
  41. if emoji['representation'] == 'text-default':
  42. hex_codepoint = emoji['codepoint'].lower() + '-fe0f'
  43. else:
  44. hex_codepoint = emoji['codepoint'].lower()
  45. print('>{}</span>'.format(make_hexchar(hex_codepoint)))
  46. for emoji in groups[category['id']]:
  47. if 'gender' in emoji and emoji['gender'] is None:
  48. # Skip gender-neutral emoji if gendered versions are available
  49. continue
  50. print_emoji(emoji)
  51. print(' </div>')
  52. print(' </div>')
  53. print(' <div class="skins">')
  54. print(' <img src="emoji/tone0.svg" width="24" height="24" data-tone="0" title="No Skin Tone" role="option" tabindex="0">')
  55. print(' <img src="emoji/tone1.svg" width="24" height="24" data-tone="1" title="Light Skin Tone" role="option" tabindex="0">')
  56. print(' <img src="emoji/tone2.svg" width="24" height="24" data-tone="2" title="Medium-Light Skin Tone" role="option" tabindex="0">')
  57. print(' <img src="emoji/tone3.svg" width="24" height="24" data-tone="3" title="Medium Skin Tone" role="option" tabindex="0">')
  58. print(' <img src="emoji/tone4.svg" width="24" height="24" data-tone="4" title="Medium-Dark Skin Tone" role="option" tabindex="0">')
  59. print(' <img src="emoji/tone5.svg" width="24" height="24" data-tone="5" title="Dark Skin Tone" role="option" tabindex="0">')
  60. print(' </div>')
  61. print('</div>')