From 2cfc89415ce8568e599f2a3500f0e19f6295936c Mon Sep 17 00:00:00 2001 From: Xie Yanbo Date: Tue, 7 Mar 2023 09:35:52 +0800 Subject: [PATCH] Fix filename (#81) * fix name issues * remove magic number --- make_book.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/make_book.py b/make_book.py index cb4dcb9..f220281 100644 --- a/make_book.py +++ b/make_book.py @@ -10,7 +10,7 @@ from pathlib import Path import openai import requests from bs4 import BeautifulSoup as bs -from ebooklib import epub +from ebooklib import epub, ITEM_DOCUMENT from rich import print from tqdm import tqdm @@ -177,7 +177,7 @@ class BEPUB: try: for i in self.origin_book.get_items(): pbar.update(index) - if i.get_type() == 9: + if i.get_type() == ITEM_DOCUMENT: soup = bs(i.content, "html.parser") p_list = soup.findAll("p") is_test_done = IS_TEST and index > TEST_NUM @@ -198,7 +198,7 @@ class BEPUB: break i.content = soup.prettify().encode() new_book.add_item(i) - name = self.epub_name.split(".")[0] + name, _ = os.path.splitext(self.epub_name) epub.write_epub(f"{name}_bilingual.epub", new_book, {}) pbar.close() except (KeyboardInterrupt, Exception) as e: @@ -312,7 +312,7 @@ if __name__ == "__main__": RESUME = options.resume if not OPENAI_API_KEY: raise Exception("Need openai API key, please google how to") - if not options.book_name.endswith(".epub"): + if not options.book_name.lower().endswith(".epub"): raise Exception("please use epub file") model = MODEL_DICT.get(options.model, "chatgpt") language = options.language