Add -tc suffix to converted file with same filename before conversion

This commit is contained in:
Tony Yang 2021-02-19 18:46:22 +08:00
parent 167fb4addb
commit 3c71e28407
Signed by: t510599
GPG Key ID: D88388851C28715D

View File

@ -58,13 +58,16 @@ if __name__ == "__main__":
for fn in fn_list: for fn in fn_list:
if not Path(fn).suffix == ".epub": if not Path(fn).suffix == ".epub":
print(f"Skipping file {fn}, which is not an epub document.") print(f"Skipping file {fn}, which is not an epub document.")
continue
elif fn == s2t(fn): elif fn == s2t(fn):
print(f"Skipping file {fn}, which has already been converted.") output_fn = fn[:-5] + '-tc.epub'
else: else:
t = time.time() output_fn = s2t(fn)
print(f"Converting {fn}")
buffer = BytesIO() t = time.time()
output = convert_epub(fn, buffer) print(f"Converting {fn}")
with open(s2t(fn), "wb") as f: buffer = BytesIO()
f.write(buffer.getvalue()) output = convert_epub(fn, buffer)
print(f"File {fn} is successfully converted. Time elapsed: {round(time.time() - t, 2)}s") with open(output_fn, "wb") as f:
f.write(buffer.getvalue())
print(f"File {fn} is successfully converted. Time elapsed: {round(time.time() - t, 2)}s")