-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgencode.py
executable file
·69 lines (57 loc) · 1.55 KB
/
gencode.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
# coding=utf-8
from requests_html import HTMLSession
import string
import re
import os
import io
import time
import json
class EmojiSplider:
def __init__(self, dbConfig = None):
self.base_url = 'https://typst.app/docs/reference/symbols/emoji/'
def start_requests(self):
with HTMLSession() as session:
r = session.get(self.base_url)
data = r.html.find('ul.symbol-grid li')
print('''
#let t-cm(id) = box[
#image(width: 1.0em, "twemoji/assets/svg/" + id + ".svg")
]
#let o-cm(id) = box[
#image(width: 1.0em, "openmoji/color/svg/" + upper(id) + ".svg")
]
#let cm-dic = (''')
for i in data:
nid = int(i.attrs['data-codepoint'])
code = i.find('button code')[0].text
if nid == 0x002a:
print(R' "ast": ("002a-fe0f-20e3", "2a-20e3"),')
elif nid == 0x0023:
print(R' "hash": ("0023-fe0f-20e3", "23-20e3"),')
else:
if nid > 0xff:
print(R' "{}": "{:04x}",'.format(code, nid))
else:
print(R' "{}": ("{:04x}", "{:02x}"),'.format(code, nid, nid))
print(''')
#let o(id) = {
let s = cm-dic.at(id)
if type(s) == "array" {
o-cm(s.at(0))
} else {
o-cm(s)
}
}
#let t(id) = {
let s = cm-dic.at(id)
if type(s) == "array" {
t-cm(s.at(1))
} else {
t-cm(s)
}
}
''')
if __name__ == '__main__':
splider = EmojiSplider()
splider.start_requests()