Last active
July 21, 2017 08:49
-
-
Save kickbase/15b8473eed1ca62090c9ccebc12b2307 to your computer and use it in GitHub Desktop.
[Python] Convert Kanji to Kana in JavaScript files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| from pathlib import Path | |
| from pykakasi import kakasi | |
| kakasi = kakasi() | |
| kakasi.setMode('H', 'a') | |
| kakasi.setMode('K', 'a') | |
| kakasi.setMode('J', 'a') | |
| conv = kakasi.getConverter() | |
| path = Path(sys.argv[1] if len(sys.argv) >= 2 else '.') | |
| for src in [f for f in path.glob('*.js') if f.is_file()]: | |
| dist = Path("_" + src.name) | |
| print('{} -> {} ...'.format(src, dist)) | |
| with src.open() as fin, dist.open('w') as fout: | |
| for line in fin: | |
| fout.write(conv.do(line)) | |
| fout.flush() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment