mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-07-19 16:40:08 +00:00
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:
parent
30669abd5a
commit
4219f9c31d
10
make_book.py
10
make_book.py
@ -6,6 +6,7 @@ from abc import abstractmethod
|
||||
from copy import copy
|
||||
from os import environ as env
|
||||
from pathlib import Path
|
||||
from tqdm import tqdm
|
||||
|
||||
import openai
|
||||
import requests
|
||||
@ -118,7 +119,7 @@ class ChatGPT(Base):
|
||||
messages=[
|
||||
{
|
||||
"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(
|
||||
[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
|
||||
p_to_save_len = len(self.p_to_save)
|
||||
try:
|
||||
for i in self.origin_book.get_items():
|
||||
pbar.update(index)
|
||||
if i.get_type() == 9:
|
||||
soup = bs(i.content, "html.parser")
|
||||
p_list = soup.findAll("p")
|
||||
@ -187,6 +192,7 @@ class BEPUB:
|
||||
new_book.add_item(i)
|
||||
name = self.epub_name.split(".")[0]
|
||||
epub.write_epub(f"{name}_bilingual.epub", new_book, {})
|
||||
pbar.close()
|
||||
except (KeyboardInterrupt, Exception) as e:
|
||||
print(e)
|
||||
print("you can resume it next time")
|
||||
|
@ -3,3 +3,4 @@ openai
|
||||
requests
|
||||
ebooklib
|
||||
rich
|
||||
tqdm
|
||||
|
Loading…
x
Reference in New Issue
Block a user