blob: d9911059d4a75722048292a9be623aef4279ec9d (
plain)
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
|
import csv
import json
import os
_root = os.path.dirname(__file__)
def _main():
dingbats = _read_dingbats()
_write_javascript_module(dingbats)
_write_python_module(dingbats)
def _read_dingbats():
with open(os.path.join(_root, "dingbats.csv")) as dingbats_file:
dingbat_reader = csv.DictReader(dingbats_file)
return list(dingbat_reader)
def _write_javascript_module(dingbats):
with _open_text_file("js/src/dingbats.ts") as typescript_file:
typescript_file.write("const dingbats = [\n")
for dingbat in dingbats:
typescript_file.write(" ")
json.dump(dingbat, typescript_file)
typescript_file.write(",\n")
typescript_file.write("];\n")
typescript_file.write("export default dingbats;\n");
def _write_python_module(dingbats):
with _open_text_file("python/dingbats.py") as python_file:
python_file.write("# Generated by https://github.com/mwilliamson/dingbat-to-unicode\n\n")
python_file.write("dingbats = {\n")
for dingbat in dingbats:
python_file.write(" ")
python_file.write(repr((dingbat["Typeface name"], int(dingbat["Dingbat dec"]))))
python_file.write(": ")
python_file.write(repr(int(dingbat["Unicode dec"])))
python_file.write(",\n")
python_file.write("}\n")
def _open_text_file(path):
full_path = os.path.join(_root, path)
os.makedirs(os.path.dirname(full_path), exist_ok=True)
return open(full_path, "wt", encoding="utf-8")
if __name__ == "__main__":
_main()
|