Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
hleft committed Mar 11, 2023
1 parent 21478d9 commit 3523469
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 11 additions & 6 deletions book_maker/loader/epub_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ def deal_old(wait_p_list):

send_num = self.accumulated_num
if send_num > 1:
print("------------------------------------------------------")
print(f"dealing {item.file_name} ...")
print("------------------------------------------------------")
count = 0
wait_p_list = []
for i in range(0, len(p_list)):
Expand Down Expand Up @@ -177,14 +180,16 @@ def deal_old(wait_p_list):

item.content = soup.prettify().encode()
new_book.add_item(item)
name, _ = os.path.splitext(self.epub_name)
epub.write_epub(f"{name}_bilingual.epub", new_book, {})
pbar.close()
name, _ = os.path.splitext(self.epub_name)
epub.write_epub(f"{name}_bilingual.epub", new_book, {})
if self.accumulated_num == 1:
pbar.close()
except (KeyboardInterrupt, Exception) as e:
print(e)
print("you can resume it next time")
self._save_progress()
self._save_temp_book()
if self.accumulated_num == 1:
print("you can resume it next time")
self._save_progress()
self._save_temp_book()
sys.exit(0)

def load_state(self):
Expand Down
5 changes: 3 additions & 2 deletions book_maker/translator/chatgptapi_translator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import re

import openai
from os import environ
Expand Down Expand Up @@ -48,7 +49,7 @@ def get_translation(self, text):

def translate(self, text):
# todo: Determine whether to print according to the cli option
print(text)
print(re.sub("\n{3,}", "\n\n", text))

try:
t_text = self.get_translation(text)
Expand All @@ -64,7 +65,7 @@ def translate(self, text):
t_text = self.get_translation(text)

# todo: Determine whether to print according to the cli option
print(t_text.strip())
print(re.sub("\n{3,}", "\n\n", t_text))
return t_text

def translate_list(self, plist):
Expand Down

0 comments on commit 3523469

Please sign in to comment.