Help improve progress bar on the book translation progress (#17)

* Update make_book.py

* Update requirements.txt

* Create main.yml

* fix error for linting

* fix error

* fix: support test of bar

---------

Co-authored-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
Kevin 2023-03-05 09:45:02 +08:00 committed by GitHub
parent 30669abd5a
commit 4219f9c31d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -6,6 +6,7 @@ from abc import abstractmethod
from copy import copy from copy import copy
from os import environ as env from os import environ as env
from pathlib import Path from pathlib import Path
from tqdm import tqdm
import openai import openai
import requests import requests
@ -118,7 +119,7 @@ class ChatGPT(Base):
messages=[ messages=[
{ {
"role": "user", "role": "user",
"content": f"Please help me to translate`{text}` to Simplified Chinese, please return only translated content not include the origin text", "content": f"Please help me to translate,`{text}` to Simplified Chinese, please return only translated content not include the origin text",
} }
], ],
) )
@ -159,11 +160,15 @@ class BEPUB:
all_p_length = sum( all_p_length = sum(
[len(bs(i.content, "html.parser").findAll("p")) for i in all_items] [len(bs(i.content, "html.parser").findAll("p")) for i in all_items]
) )
print("TODO need process bar here: " + str(all_p_length)) if IS_TEST:
pbar = tqdm(total=TEST_NUM)
else:
pbar = tqdm(total=all_p_length)
index = 0 index = 0
p_to_save_len = len(self.p_to_save) p_to_save_len = len(self.p_to_save)
try: try:
for i in self.origin_book.get_items(): for i in self.origin_book.get_items():
pbar.update(index)
if i.get_type() == 9: if i.get_type() == 9:
soup = bs(i.content, "html.parser") soup = bs(i.content, "html.parser")
p_list = soup.findAll("p") p_list = soup.findAll("p")
@ -187,6 +192,7 @@ class BEPUB:
new_book.add_item(i) new_book.add_item(i)
name = self.epub_name.split(".")[0] name = self.epub_name.split(".")[0]
epub.write_epub(f"{name}_bilingual.epub", new_book, {}) epub.write_epub(f"{name}_bilingual.epub", new_book, {})
pbar.close()
except (KeyboardInterrupt, Exception) as e: except (KeyboardInterrupt, Exception) as e:
print(e) print(e)
print("you can resume it next time") print("you can resume it next time")

View File

@ -2,4 +2,5 @@ bs4
openai openai
requests requests
ebooklib ebooklib
rich rich
tqdm