| 1 | import json |
| 2 | from urllib.request import urlopen |
| 3 | |
| 4 | |
| 5 | def get_gemojione(): |
| 6 | remote = 'https://raw.githubusercontent.com/bonusly/gemojione/master' |
| 7 | data = json.load(urlopen(remote + '/config/index.json')) |
| 8 | codes = {} |
| 9 | for emoji in data.values(): |
| 10 | codes[emoji['shortname']] = emoji['moji'] |
| 11 | for alias in emoji['aliases']: |
| 12 | codes[alias] = emoji['moji'] |
| 13 | return codes |
| 14 | |
| 15 | |
| 16 | def get_joypixels(): |
| 17 | remote = 'https://raw.githubusercontent.com/joypixels/emoji-toolkit/master' |
| 18 | data = json.load(urlopen(remote + '/emoji.json')) |
| 19 | codes = {} |
| 20 | for info in data.values(): |
| 21 | hexstring = info['code_points']['fully_qualified'] |
| 22 | emoji = ''.join(chr(int(c, 16)) for c in hexstring.split('-')) |
| 23 | codes[info['shortname']] = emoji |
| 24 | for alias in info['shortname_alternates']: |
| 25 | codes[alias] = emoji |
| 26 | return codes |
| 27 | |
| 28 | |
| 29 | def update_codes(): |
| 30 | with open('sphinxemoji/codes.json') as current: |
| 31 | codes = json.load(current) |
| 32 | for getter in [ |
| 33 | get_gemojione, |
| 34 | get_joypixels, |
| 35 | ]: |
| 36 | codes.update(getter()) |
| 37 | with open('sphinxemoji/codes.json', 'w') as output: |
| 38 | json.dump(codes, output, sort_keys=True, indent=4, ensure_ascii=False) |
| 39 | output.write('\n') |
| 40 | |
| 41 | |
| 42 | if __name__ == '__main__': |
| 43 | update_codes() |