Skip to content

Commit

Permalink
Help improve progress bar on the book translation progress (#17)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
kj-huang and yihong0618 authored Mar 5, 2023
1 parent 30669ab commit 4219f9c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions make_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from copy import copy
from os import environ as env
from pathlib import Path
from tqdm import tqdm

import openai
import requests
Expand Down Expand Up @@ -118,7 +119,7 @@ def translate(self, text):
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",
}
],
)
Expand Down Expand Up @@ -159,11 +160,15 @@ def make_bilingual_book(self):
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")
Expand All @@ -187,6 +192,7 @@ def make_bilingual_book(self):
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")
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ bs4
openai
requests
ebooklib
rich
rich
tqdm

0 comments on commit 4219f9c

Please sign in to comment.