fix ntfy
This commit is contained in:
parent
3d00520c14
commit
99b2dabd1d
@ -2,6 +2,7 @@ import os
|
||||
from pathlib import Path
|
||||
from zipfile import ZipFile
|
||||
from utils.comic.ComicInfo import comicInfo
|
||||
from utils.Ntfy import ntfy
|
||||
|
||||
class CBZUtils:
|
||||
|
||||
@ -35,7 +36,7 @@ class CBZUtils:
|
||||
print("打包中:" + str(y) + "/" + str(len(filenames)), os.path.join(source_dir, filename))
|
||||
zf.write(path.joinpath(filename), arc_dir.joinpath(filename))
|
||||
zf.close()
|
||||
print("打包完成:", target_file)
|
||||
ntfy.sendMsg("打包完成:", target_file)
|
||||
#md5_file = md5(target_file)
|
||||
#print("md5:", md5_file)
|
||||
#msg[target_file] = md5_file
|
||||
|
||||
@ -5,6 +5,7 @@ import traceback
|
||||
import time
|
||||
from urllib3.util.retry import Retry
|
||||
from requests.adapters import HTTPAdapter
|
||||
from utils.Ntfy import ntfy
|
||||
|
||||
class htmlUtils:
|
||||
headers = {'User-Agent': UserAgent().random}
|
||||
@ -27,20 +28,20 @@ class htmlUtils:
|
||||
while url_text == None:
|
||||
if count <= 10:
|
||||
try:
|
||||
print("请求地址:",curl)
|
||||
ntfy.sendMsg(f"请求地址:{curl}")
|
||||
res = s.get(curl,stream=True, headers=cls.headers, timeout=50)
|
||||
if type == "bytes":
|
||||
url_text = res
|
||||
else:
|
||||
url_text = html.fromstring(res.text)
|
||||
except:
|
||||
print(f'Retry! 第{count}次')
|
||||
ntfy.sendMsg(f'Retry! 第{count}次')
|
||||
time.sleep(3)
|
||||
traceback.print_exc()
|
||||
count += 1
|
||||
continue
|
||||
else:
|
||||
print(f"fail 请求失败:{curl}")
|
||||
ntfy.sendMsg(f"fail 请求失败:{curl}")
|
||||
break
|
||||
if type == "None":
|
||||
data = { curl : url_text}
|
||||
@ -60,7 +61,7 @@ class htmlUtils:
|
||||
data_json = res.json()
|
||||
return data_json
|
||||
except:
|
||||
print(f"请求失败,重试中...")
|
||||
ntfy.sendMsg(f"请求失败,重试中... {curl}")
|
||||
count += 1
|
||||
time.sleep(1)
|
||||
cls.getJSON(curl)
|
||||
|
||||
@ -91,10 +91,4 @@ class netUtils:
|
||||
save_path = os.path.join(pathCBZComic,comicInfo.getChapter()+icon_su)
|
||||
shutil.copy(pathComicIcon, save_path)
|
||||
print(f"{pathComicIcon} 已复制至: {save_path}")
|
||||
comicInfo.nextDownloadToCBZChapter()
|
||||
|
||||
@classmethod
|
||||
def sendMsg(cls, msg):
|
||||
print(f"#ntfy: {msg}")
|
||||
requests.post("https://ntfy.caiwenxiu.cn/PyComic",
|
||||
data=msg.encode(encoding='utf-8'))
|
||||
comicInfo.nextDownloadToCBZChapter()
|
||||
8
utils/Ntfy.py
Normal file
8
utils/Ntfy.py
Normal file
@ -0,0 +1,8 @@
|
||||
import requests
|
||||
|
||||
class ntfy:
|
||||
@classmethod
|
||||
def sendMsg(cls, msg):
|
||||
print(f"#ntfy: {msg}")
|
||||
requests.post("https://ntfy.caiwenxiu.cn/PyComic",
|
||||
data=msg.encode(encoding='utf-8'))
|
||||
@ -11,6 +11,7 @@ import os
|
||||
import concurrent.futures
|
||||
import requests
|
||||
import time
|
||||
from utils.Ntfy import ntfy
|
||||
|
||||
headers = {
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
|
||||
@ -39,7 +40,7 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p
|
||||
image_url, headers=headers, timeout=timeout, proxies=proxies)
|
||||
while response.status_code != 200 and repair_count <= 5:
|
||||
download_image(image_url,dst_dir,file_name)
|
||||
print(f'重试:第{repair_count}次 {image_url}')
|
||||
ntfy.sendMsg(f'重试:第{repair_count}次 {image_url}')
|
||||
repair_count += 1
|
||||
with open(temp_path, 'wb') as f:
|
||||
f.write(response.content)
|
||||
@ -51,7 +52,7 @@ def download_image(image_url, dst_dir, file_name, timeout=20, proxy_type=None, p
|
||||
response.close()
|
||||
if repair_count < 5:
|
||||
time.sleep(1)
|
||||
print("## Repeat: {} {}".format(image_url))
|
||||
ntfy.sendMsg("## Repeat: {} {}".format(image_url))
|
||||
download_image(image_url,dst_dir,file_name)
|
||||
repair_count += 1
|
||||
else:
|
||||
|
||||
@ -5,6 +5,7 @@ from utils.ImageUtils import imageUtils
|
||||
from utils.comic.ComicInfo import comicInfo
|
||||
from utils.CBZUtils import CBZUtils
|
||||
from utils.downloader import download_images
|
||||
from utils.Ntfy import ntfy
|
||||
|
||||
class comicEntity:
|
||||
|
||||
@ -33,7 +34,7 @@ class comicEntity:
|
||||
comicInfo.setComicName(book_name)
|
||||
#dirConfComic = comicInfo.getDirConfComic()
|
||||
#if not os.path.exists(dirConfComic):
|
||||
netUtils.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}")
|
||||
ntfy.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}")
|
||||
time.sleep(random_int)
|
||||
cls.oneComic(comicHref, random.uniform(0,3))
|
||||
|
||||
@ -106,14 +107,14 @@ class comicEntity:
|
||||
#完成删除原文件
|
||||
remove_path = comicInfo.getDirComicChapter()
|
||||
shutil.rmtree(remove_path)
|
||||
netUtils.sendMsg(f"文件已删除: {remove_path}")
|
||||
ntfy.sendMsg(f"文件已删除: {remove_path}")
|
||||
except:
|
||||
dirComicChapter = comicInfo.getDirComicChapter
|
||||
if not dirComicChapter == None and os.path.exists(dirComicChapter):
|
||||
shutil.rmtree(dirComicChapter)
|
||||
cls.comicChapter(chapter_url,scramble,sleep)
|
||||
if not sleep == None:
|
||||
netUtils.sendMsg(f"{sleep} 秒后开始下载下一个章节")
|
||||
ntfy.sendMsg(f"{sleep} 秒后开始下载下一个章节")
|
||||
time.sleep(sleep)
|
||||
|
||||
@classmethod
|
||||
@ -149,7 +150,7 @@ class comicEntity:
|
||||
description = x.get("description")
|
||||
images = x.get("images")
|
||||
chapterAPIPath = x.get("chapterAPIPath")
|
||||
netUtils.sendMsg(f"{bookName} {chapterName} 下载中")
|
||||
ntfy.sendMsg(f"{bookName} {chapterName} 下载中")
|
||||
comicInfo.setComicName(bookName)
|
||||
comicInfo.setChapterName(chapterName)
|
||||
comicInfo.setDep(description)
|
||||
@ -166,7 +167,7 @@ class comicEntity:
|
||||
chapterName = data.get("name")
|
||||
images = data.get("images")
|
||||
if images == None:
|
||||
netUtils.sendMsg(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}")
|
||||
ntfy.sendMsg(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}")
|
||||
totalChapter = x.get("totalChapter")
|
||||
tags = x.get("tags")
|
||||
x = tags
|
||||
|
||||
Loading…
Reference in New Issue
Block a user