| 1 | import os |
| 2 | import sys |
| 3 | from os import path |
| 4 | from fontTools.ttLib import TTFont |
| 5 | import shutil |
| 6 | |
| 7 | ttf_path = os.path.abspath(os.getcwd()) + "\\" +sys.argv[1] |
| 8 | os.chdir(ttf_path) |
| 9 | |
| 10 | for file in os.listdir(): |
| 11 | if file.endswith(".ttf"): |
| 12 | f = TTFont(file) |
| 13 | f.flavor='woff2' |
| 14 | f.save(os.path.splitext(file)[0]+".woff2") |
| 15 | |
| 16 | if not path.exists("woff2"): |
| 17 | os.mkdir("woff2") |
| 18 | sourcefiles = os.listdir(ttf_path) |
| 19 | destenation_path = ttf_path + "\woff2" |
| 20 | for file in sourcefiles: |
| 21 | if file.endswith('.woff2'): |
| 22 | shutil.move(os.path.join(ttf_path,file), os.path.join(destenation_path,file)) |