diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..fa01656 --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +opencc = "*" +click = "*" + +[dev-packages] + +[requires] +python_version = "3.6" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..f5a95c2 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,36 @@ +{ + "_meta": { + "hash": { + "sha256": "e11e067f853c70dd2660c4e3d606219472ef597161bcf00ffcd63872df1183bf" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.6" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "click": { + "hashes": [ + "sha256:d2b5255c7c6349bc1bd1e59e08cd12acbbd63ce649f2588755783aa94dfb6b1a", + "sha256:dacca89f4bfadd5de3d7489b7c8a566eee0d3676333fbb50030263894c38c0dc" + ], + "index": "pypi", + "version": "==7.1.2" + }, + "opencc": { + "hashes": [ + "sha256:1e0d40581dd5130ac3160f97e752caff202aa22aa004d468496fa8cba81035e7" + ], + "index": "pypi", + "version": "==1.1.1.post1" + } + }, + "develop": {} +} diff --git a/transform.py b/transform.py new file mode 100644 index 0000000..6465e84 --- /dev/null +++ b/transform.py @@ -0,0 +1,21 @@ +"""Convert zh-cn to zh-tw +Refer to https://github.com/BYVoid/OpenCC +""" +import click +import opencc + + +@click.command() +@click.option("-i", "--input", "infile", required=True) +@click.option("-o", "--output", "outfile", required=True) +@click.option("-c", "--config", "cfg", required=True, default="s2twp.json") +def main(infile, outfile, cfg): + converter = opencc.OpenCC(cfg) + with open(infile, "r") as inf, open(outfile, "w+") as outf: + data = inf.readlines() + data = list(map(converter.convert, data)) + outf.writelines(data) + + +if __name__ == "__main__": + main()