This commit is contained in:
caiwx86 2023-03-31 19:57:15 +08:00
parent 9723c6b994
commit a7cfeae7eb
2 changed files with 9 additions and 12 deletions

View File

@ -37,8 +37,7 @@ class comicCommon:
data = htmlUtils.getJSON(chapter_api_url) data = htmlUtils.getJSON(chapter_api_url)
if data != None: if data != None:
data = data.get("chapter") data = data.get("chapter")
chapter_name = data.get("name") (chapter_name,images) = [data.get("name"),data.get("images")]
images = data.get("images")
if images == None: if images == None:
ntfy.sendMsg(f"未获取到章节图像 comic_name={book_name} chapter={chapter_name}") ntfy.sendMsg(f"未获取到章节图像 comic_name={book_name} chapter={chapter_name}")

View File

@ -25,6 +25,7 @@ class htmlUtils:
return file_path return file_path
if os.path.exists(file_path): if os.path.exists(file_path):
if type == "read": if type == "read":
print(f"读取cache: {file_path}")
with open(file_path,"r",encoding="utf-8") as fs: with open(file_path,"r",encoding="utf-8") as fs:
return fs.read() return fs.read()
return file_path return file_path
@ -32,12 +33,13 @@ class htmlUtils:
return None return None
@classmethod @classmethod
def saveHtml(cls,url,data): def saveHtml(cls,url,data,type=None):
file_path = cls.getPathSaveHtml(url,type="new") file_path = cls.getPathSaveHtml(url,type="new")
dir_name = os.path.dirname(file_path) dir_name = os.path.dirname(file_path)
if not os.path.exists(dir_name): if not os.path.exists(dir_name):
os.makedirs(dir_name) os.makedirs(dir_name)
with open(file_path,"w",encoding="utf-8") as fs: with open(file_path,"w",encoding="utf-8") as fs:
if type== "json": data = json.dumps(data)
fs.write(str(data)) fs.write(str(data))
@classmethod @classmethod
@ -61,14 +63,10 @@ class htmlUtils:
s.mount('https://', HTTPAdapter(max_retries=retries)) s.mount('https://', HTTPAdapter(max_retries=retries))
count = 1 count = 1
#数据为空则获取数据 #数据为空则获取数据
try: try: url_text = cls.getPathSaveHtml(curl,"read")
url_text = cls.getPathSaveHtml(curl,"read") except: url_text = None
except: if url_text != None and update == False: return html.fromstring(url_text)
url_text = None else: url_text = None
if url_text != None and update == False:
return html.fromstring(url_text)
else:
url_text = None
while url_text == None: while url_text == None:
if count <= 5: if count <= 5:
try: try:
@ -82,7 +80,7 @@ class htmlUtils:
if type == "json": if type == "json":
#url_text = res.json() #url_text = res.json()
try: try:
cls.saveHtml(curl,res.text) cls.saveHtml(curl,res.text,type="json")
return json.loads(res.text) return json.loads(res.text)
except: except:
return None return None