fix
This commit is contained in:
parent
9723c6b994
commit
a7cfeae7eb
@ -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}")
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user