File: utils.py

package info (click to toggle)
buskill 0.7.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 30,984 kB
  • sloc: python: 3,187; sh: 85; makefile: 22; javascript: 9
file content (43 lines) | stat: -rw-r--r-- 1,297 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
from urllib.request import urlopen


def get_gemojione():
    remote = 'https://raw.githubusercontent.com/bonusly/gemojione/master'
    data = json.load(urlopen(remote + '/config/index.json'))
    codes = {}
    for emoji in data.values():
        codes[emoji['shortname']] = emoji['moji']
        for alias in emoji['aliases']:
            codes[alias] = emoji['moji']
    return codes


def get_joypixels():
    remote = 'https://raw.githubusercontent.com/joypixels/emoji-toolkit/master'
    data = json.load(urlopen(remote + '/emoji.json'))
    codes = {}
    for info in data.values():
        hexstring = info['code_points']['fully_qualified']
        emoji = ''.join(chr(int(c, 16)) for c in hexstring.split('-'))
        codes[info['shortname']] = emoji
        for alias in info['shortname_alternates']:
            codes[alias] = emoji
    return codes


def update_codes():
    with open('sphinxemoji/codes.json') as current:
        codes = json.load(current)
    for getter in [
        get_gemojione,
        get_joypixels,
    ]:
        codes.update(getter())
    with open('sphinxemoji/codes.json', 'w') as output:
        json.dump(codes, output, sort_keys=True, indent=4, ensure_ascii=False)
        output.write('\n')


if __name__ == '__main__':
    update_codes()