Merge pull request #1 from t510599/master
reduced unnecessary import when being used as lib
This commit is contained in:
commit
6016042419
11
convert.py
11
convert.py
@ -1,9 +1,5 @@
|
|||||||
import argparse
|
|
||||||
import zipfile
|
import zipfile
|
||||||
import opencc
|
import opencc
|
||||||
import glob
|
|
||||||
import time
|
|
||||||
from io import BytesIO
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# only initailize OpenCC once, or it would be very slow
|
# only initailize OpenCC once, or it would be very slow
|
||||||
@ -45,6 +41,11 @@ def s2t(text):
|
|||||||
return converter.convert(text)
|
return converter.convert(text)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
import argparse
|
||||||
|
import glob
|
||||||
|
import time
|
||||||
|
from io import BytesIO
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Convert simplified chinese to traditional chinese in epub.")
|
parser = argparse.ArgumentParser(description="Convert simplified chinese to traditional chinese in epub.")
|
||||||
parser.add_argument('file', nargs='+', help="epub files")
|
parser.add_argument('file', nargs='+', help="epub files")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@ -66,4 +67,4 @@ if __name__ == "__main__":
|
|||||||
output = convert_epub(fn, buffer)
|
output = convert_epub(fn, buffer)
|
||||||
with open(s2t(fn), "wb") as f:
|
with open(s2t(fn), "wb") as f:
|
||||||
f.write(buffer.getvalue())
|
f.write(buffer.getvalue())
|
||||||
print(f"File {fn} is successfully converted. Time elapsed: {round(time.time() - t, 2)}s")
|
print(f"File {fn} is successfully converted. Time elapsed: {round(time.time() - t, 2)}s")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user