Debian Codegraph @

tools/gen_joypixels.py

raw
1 """Generate emojione data."""
2 import os
3 import json
4 current_dir = os.path.dirname(os.path.abspath(__file__))
5 LICENSE = """
6 MIT license.
7
8 Copyright (c) http://www.emojione.com
9 """
10
11
12 def get_unicode_alt(value):
13 """Get alternate Unicode form or return the original."""
14
15 return value['code_points']['fully_qualified']
16
17
18 def parse(repo, tag):
19 """Save test files."""
20 # Load emoji database
21 with open(os.path.join(current_dir, 'tags', repo, repo, 'emoji.json')) as f:
22 emojis = json.loads(f.read())
23
24 emoji_db = {}
25 shortnames = set()
26 aliases = {}
27 for v in emojis.values():
28 shortnames.add(v['shortname'])
29 emoji_db[v['shortname']] = {
30 'name': v['name'],
31 'unicode': v['code_points']['base'],
32 'category': v['category']
33 }
34 alt = get_unicode_alt(v)
35 if alt and alt != v['code_points']['base']:
36 emoji_db[v['shortname']]['unicode_alt'] = alt
37
38 for alias in v['shortname_alternates']:
39 aliases[alias] = v['shortname']
40
41 return emoji_db, aliases