diff options
Diffstat (limited to 'generate.py')
| -rw-r--r-- | generate.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/generate.py b/generate.py index 2b9b716..d991105 100644 --- a/generate.py +++ b/generate.py @@ -10,6 +10,7 @@ def _main(): dingbats = _read_dingbats() _write_javascript_module(dingbats) + _write_python_module(dingbats) def _read_dingbats(): @@ -20,7 +21,7 @@ def _read_dingbats(): def _write_javascript_module(dingbats): - with open(os.path.join(_root, "js/src/dingbats.ts"), "wt", encoding="utf-8") as typescript_file: + with _open_text_file("js/src/dingbats.ts") as typescript_file: typescript_file.write("const dingbats = [\n") for dingbat in dingbats: @@ -32,5 +33,26 @@ def _write_javascript_module(dingbats): 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() |
