mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-07-29 06:11:44 +00:00
fix: ruff it
Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
parent
938555ead8
commit
ba04ff04fe
@ -402,7 +402,7 @@ So you are close to reaching the limit. You have to choose your own value, there
|
||||
options = parser.parse_args()
|
||||
|
||||
if not options.book_name:
|
||||
print(f"Error: please provide the path of your book using --book_name <path>")
|
||||
print("Error: please provide the path of your book using --book_name <path>")
|
||||
exit(1)
|
||||
if not os.path.isfile(options.book_name):
|
||||
print(f"Error: the book {options.book_name!r} does not exist.")
|
||||
|
@ -137,7 +137,7 @@ class EPUBBookLoader(BaseBookLoader):
|
||||
def _extract_paragraph(self, p):
|
||||
for p_exclude in self.exclude_translate_tags.split(","):
|
||||
# for issue #280
|
||||
if type(p) == NavigableString:
|
||||
if type(p) is NavigableString:
|
||||
continue
|
||||
for pt in p.find_all(p_exclude):
|
||||
pt.extract()
|
||||
@ -154,7 +154,7 @@ class EPUBBookLoader(BaseBookLoader):
|
||||
t_text = self.translate_model.batch_translate(index)
|
||||
else:
|
||||
t_text = self.translate_model.translate(new_p.text)
|
||||
if type(p) == NavigableString:
|
||||
if type(p) is NavigableString:
|
||||
new_p = t_text
|
||||
self.p_to_save.append(new_p)
|
||||
else:
|
||||
@ -198,7 +198,7 @@ class EPUBBookLoader(BaseBookLoader):
|
||||
else:
|
||||
p = p_block[i]
|
||||
|
||||
if type(p) == NavigableString:
|
||||
if type(p) is NavigableString:
|
||||
p = t
|
||||
else:
|
||||
p.string = t
|
||||
@ -220,7 +220,7 @@ class EPUBBookLoader(BaseBookLoader):
|
||||
|
||||
for p_exclude in self.exclude_translate_tags.split(","):
|
||||
# for issue #280
|
||||
if type(p) == NavigableString:
|
||||
if type(p) is NavigableString:
|
||||
continue
|
||||
for pt in temp_p.find_all(p_exclude):
|
||||
pt.extract()
|
||||
@ -381,7 +381,7 @@ class EPUBBookLoader(BaseBookLoader):
|
||||
fixstart=None,
|
||||
fixend=None,
|
||||
):
|
||||
if self.only_filelist != "" and not item.file_name in self.only_filelist.split(
|
||||
if self.only_filelist != "" and item.file_name not in self.only_filelist.split(
|
||||
","
|
||||
):
|
||||
return index
|
||||
@ -587,7 +587,7 @@ class EPUBBookLoader(BaseBookLoader):
|
||||
# PR welcome here
|
||||
if index < p_to_save_len:
|
||||
new_p = copy(p)
|
||||
if type(p) == NavigableString:
|
||||
if type(p) is NavigableString:
|
||||
new_p = self.p_to_save[index]
|
||||
else:
|
||||
new_p.string = self.p_to_save[index]
|
||||
|
@ -160,8 +160,8 @@ class MarkdownBookLoader(BaseBookLoader):
|
||||
try:
|
||||
with open(self.bin_path, "w", encoding="utf-8") as f:
|
||||
f.write("\n".join(self.p_to_save))
|
||||
except:
|
||||
raise Exception("can not save resume file")
|
||||
except Exception as e:
|
||||
raise Exception("can not save resume file") from e
|
||||
|
||||
def load_state(self):
|
||||
try:
|
||||
@ -174,5 +174,5 @@ class MarkdownBookLoader(BaseBookLoader):
|
||||
try:
|
||||
with open(book_path, "w", encoding="utf-8") as f:
|
||||
f.write("\n".join(content))
|
||||
except:
|
||||
raise Exception("can not save file")
|
||||
except Exception as e:
|
||||
raise Exception("can not save file") from e
|
||||
|
@ -215,7 +215,7 @@ class SRTBookLoader(BaseBookLoader):
|
||||
translated_blocks, self.blocks[begin:end]
|
||||
):
|
||||
raise Exception(
|
||||
f"retry failed, adjust the srt manually."
|
||||
"retry failed, adjust the srt manually."
|
||||
)
|
||||
|
||||
for i, block in enumerate(translated_blocks):
|
||||
@ -276,8 +276,8 @@ class SRTBookLoader(BaseBookLoader):
|
||||
try:
|
||||
with open(self.bin_path, "w", encoding="utf-8") as f:
|
||||
f.write("===".join(self.p_to_save))
|
||||
except:
|
||||
raise Exception("can not save resume file")
|
||||
except Exception as e:
|
||||
raise Exception("can not save resume file") from e
|
||||
|
||||
def load_state(self):
|
||||
try:
|
||||
@ -295,5 +295,5 @@ class SRTBookLoader(BaseBookLoader):
|
||||
try:
|
||||
with open(book_path, "w", encoding="utf-8") as f:
|
||||
f.write("\n\n".join(content))
|
||||
except:
|
||||
raise Exception("can not save file")
|
||||
except Exception as e:
|
||||
raise Exception("can not save file") from e
|
||||
|
@ -125,8 +125,8 @@ class TXTBookLoader(BaseBookLoader):
|
||||
try:
|
||||
with open(self.bin_path, "w", encoding="utf-8") as f:
|
||||
f.write("\n".join(self.p_to_save))
|
||||
except:
|
||||
raise Exception("can not save resume file")
|
||||
except Exception as e:
|
||||
raise Exception("can not save resume file") from e
|
||||
|
||||
def load_state(self):
|
||||
try:
|
||||
@ -139,5 +139,5 @@ class TXTBookLoader(BaseBookLoader):
|
||||
try:
|
||||
with open(book_path, "w", encoding="utf-8") as f:
|
||||
f.write("\n".join(content))
|
||||
except:
|
||||
raise Exception("can not save file")
|
||||
except Exception as e:
|
||||
raise Exception("can not save file") from e
|
||||
|
@ -1,5 +1,4 @@
|
||||
import re
|
||||
import time
|
||||
from rich import print
|
||||
from anthropic import Anthropic
|
||||
|
||||
|
@ -16,7 +16,6 @@ class DeepLFree(Base):
|
||||
|
||||
def __init__(self, key, language, **kwargs) -> None:
|
||||
super().__init__(key, language)
|
||||
l = None
|
||||
l = language if language in LANGUAGES else TO_LANGUAGE_CODE.get(language)
|
||||
if l not in [
|
||||
"bg",
|
||||
|
@ -23,7 +23,6 @@ class DeepL(Base):
|
||||
"X-RapidAPI-Key": "",
|
||||
"X-RapidAPI-Host": "dpl-translator.p.rapidapi.com",
|
||||
}
|
||||
l = None
|
||||
l = language if language in LANGUAGES else TO_LANGUAGE_CODE.get(language)
|
||||
if l not in [
|
||||
"bg",
|
||||
|
@ -2,7 +2,7 @@ import re
|
||||
import requests
|
||||
from rich import print
|
||||
|
||||
from book_maker.utils import TO_LANGUAGE_CODE, LANGUAGES
|
||||
from book_maker.utils import TO_LANGUAGE_CODE
|
||||
from .base_translator import Base
|
||||
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
import re
|
||||
import time
|
||||
from os import environ
|
||||
from rich import print
|
||||
from openai import OpenAI
|
||||
|
||||
@ -100,7 +99,7 @@ class QwenTranslator(Base):
|
||||
self.context_translated_list = []
|
||||
self.context_paragraph_limit = context_paragraph_limit
|
||||
|
||||
print(f"[bold blue]Qwen Translator initialized:[/bold blue]")
|
||||
print("[bold blue]Qwen Translator initialized:[/bold blue]")
|
||||
print(f" Model: {self.model}")
|
||||
print(f" Source Language: {self.source_lang}")
|
||||
print(f" Target Language: {self.target_lang}")
|
||||
|
@ -1,7 +1,5 @@
|
||||
from openai import OpenAI
|
||||
from .chatgptapi_translator import ChatGPTAPI
|
||||
from os import linesep
|
||||
from itertools import cycle
|
||||
|
||||
|
||||
XAI_MODEL_LIST = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user