From a7cfeae7eb39a6d7e63501f14bd5cd3d1845feb8 Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Fri, 31 Mar 2023 19:57:15 +0800 Subject: [PATCH] fix --- entity/down/RouMan.py | 3 +-- utils/HtmlUtils.py | 18 ++++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/entity/down/RouMan.py b/entity/down/RouMan.py index 0fbad12..7fd8da7 100644 --- a/entity/down/RouMan.py +++ b/entity/down/RouMan.py @@ -37,8 +37,7 @@ class comicCommon: data = htmlUtils.getJSON(chapter_api_url) if data != None: data = data.get("chapter") - chapter_name = data.get("name") - images = data.get("images") + (chapter_name,images) = [data.get("name"),data.get("images")] if images == None: ntfy.sendMsg(f"未获取到章节图像 comic_name={book_name} chapter={chapter_name}") diff --git a/utils/HtmlUtils.py b/utils/HtmlUtils.py index acf425b..803f48e 100644 --- a/utils/HtmlUtils.py +++ b/utils/HtmlUtils.py @@ -25,6 +25,7 @@ class htmlUtils: return file_path if os.path.exists(file_path): if type == "read": + print(f"读取cache: {file_path}") with open(file_path,"r",encoding="utf-8") as fs: return fs.read() return file_path @@ -32,12 +33,13 @@ class htmlUtils: return None @classmethod - def saveHtml(cls,url,data): + def saveHtml(cls,url,data,type=None): file_path = cls.getPathSaveHtml(url,type="new") dir_name = os.path.dirname(file_path) if not os.path.exists(dir_name): os.makedirs(dir_name) with open(file_path,"w",encoding="utf-8") as fs: + if type== "json": data = json.dumps(data) fs.write(str(data)) @classmethod @@ -61,14 +63,10 @@ class htmlUtils: s.mount('https://', HTTPAdapter(max_retries=retries)) count = 1 #数据为空则获取数据 - try: - url_text = cls.getPathSaveHtml(curl,"read") - except: - url_text = None - if url_text != None and update == False: - return html.fromstring(url_text) - else: - url_text = None + try: url_text = cls.getPathSaveHtml(curl,"read") + except: url_text = None + if url_text != None and update == False: return html.fromstring(url_text) + else: url_text = None while url_text == None: if count <= 5: try: @@ -82,7 +80,7 @@ class htmlUtils: if type == "json": #url_text = res.json() try: - cls.saveHtml(curl,res.text) + cls.saveHtml(curl,res.text,type="json") return json.loads(res.text) except: return None