create_ruleset.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8; -*-
  3. # This is autogenerated python file DO NOT try to edit
  4. /* [[[cog
  5. import cog
  6. import json
  7. json_package_path = '../../../emoji.json'
  8. data_dict = json.loads(open(json_package_path).read())
  9. unicode_replace = {}
  10. shortcode_replace = {}
  11. ascii_replace = {}
  12. for key, value in data_dict.items():
  13. unicode_hex = value['unicode']
  14. ascii_list = value['aliases_ascii']
  15. shortname = value['shortname']
  16. for ascii in ascii_list:
  17. ascii_replace[ascii] = unicode_hex
  18. shortcode_replace[shortname] = unicode_hex
  19. if '-' not in unicode_hex:
  20. unicode_char = chr(int(unicode_hex, 16))
  21. unicode_replace[unicode_char.encode('utf-8')] = shortname
  22. else:
  23. parts = unicode_hex.split('-')
  24. unicode_char = ''.join(chr(int(part, 16)) for part in parts)
  25. unicode_replace[unicode_char.encode('utf-8')] = shortname
  26. print(unicode_replace)
  27. print(shortcode_replace)
  28. print(ascii_replace)
  29. cog.out('unicode_replace = %s\n\n' % unicode_replace)
  30. cog.out('shortcode_replace = %s\n\n' % shortcode_replace)
  31. cog.out('ascii_replace = %s\n\n' % ascii_replace)
  32. ]]] */
  33. //[[[end]]]