generate-emoji-picker.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env python3
  2. from collections import defaultdict
  3. import json
  4. # Load and group emoji data
  5. with open('emoji.json', 'r') as f:
  6. emoji_data = json.loads(f.read())
  7. groups = defaultdict(list)
  8. for k, details in emoji_data.items():
  9. groups[details['category']].append((k, details))
  10. # Define category order
  11. category_order = [
  12. {'id': 'people', 'name': 'Smileys & People', 'icon': '1f604'},
  13. {'id': 'nature', 'name': 'Animals & Nature', 'icon': '1f426'},
  14. {'id': 'food', 'name': 'Food & Drink', 'icon': '1f354'},
  15. {'id': 'activity', 'name': 'Activity', 'icon': '26bd'},
  16. {'id': 'travel', 'name': 'Travel & Places', 'icon': '2708'},
  17. {'id': 'objects', 'name': 'Objects', 'icon': '1f4a1'},
  18. {'id': 'symbols', 'name': 'Symbols', 'icon': '1f523'},
  19. {'id': 'flags', 'name': 'Flags', 'icon': '1f1ec-1f1e7'},
  20. ]
  21. # Helper functions
  22. def make_hexchar(codepoint):
  23. return '&#x%s;' % codepoint.replace('-', ';&#x')
  24. # Generate HTML
  25. print('<div class="emojione-picker">')
  26. for i, category in enumerate(category_order):
  27. print(' <div class="tab">')
  28. print(' <input type="radio" id="tab-%d" name="tabs"%s>' % (i, ' checked' if i == 0 else ''))
  29. print(' <label for="tab-%d" title="%s">' % (i, category['name']))
  30. print(' <span class="e1 e1-{0} _{1}">{2}</span>'.format(category['id'], category['icon'], make_hexchar(category['icon'])))
  31. print(' </label>')
  32. print(' <div class="content">')
  33. for emoji in groups[category['id']]:
  34. print(' <span class="e1 e1-{0} _{1}" data-c="{2}" data-s="{3}" title="{4}">{5}</span>'.format(
  35. category['id'] if not emoji[1]['diversity'] else 'diversity',
  36. emoji[0],
  37. emoji[1]['code_points']['greedy_matches'][0],
  38. emoji[1]['shortname'],
  39. emoji[1]['shortname'],
  40. make_hexchar(emoji[1]['code_points']['greedy_matches'][0]),
  41. ))
  42. print(' </div>')
  43. print(' </div>')
  44. print('</div>')