From 3d00520c149230d6e688b4e97bff425d620c423a Mon Sep 17 00:00:00 2001 From: cwx Date: Tue, 13 Dec 2022 00:09:05 +0800 Subject: [PATCH 1/6] Merge branch 'main' of https://git.caiwenxiu.cn/cwx/PyComicPackRouMan --- utils/NetUtils.py | 6 ++++++ utils/entity/RouMan.py | 21 +++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/utils/NetUtils.py b/utils/NetUtils.py index f7204ce..967d461 100644 --- a/utils/NetUtils.py +++ b/utils/NetUtils.py @@ -92,3 +92,9 @@ class netUtils: 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')) \ No newline at end of file diff --git a/utils/entity/RouMan.py b/utils/entity/RouMan.py index 362f01d..4987c8e 100644 --- a/utils/entity/RouMan.py +++ b/utils/entity/RouMan.py @@ -29,13 +29,13 @@ class comicEntity: book_name = book.get("name") updatedAt = book.get("updatedAt") comicHref = baseUrl+"/books/"+book_id - random_int = random.uniform(5,20) + random_int = random.randint(5,20) comicInfo.setComicName(book_name) - dirConfComic = comicInfo.getDirConfComic() - if not os.path.exists(dirConfComic): - print(f"{random_int}秒后开始下载 漫画:{book_name}") - time.sleep(random_int) - cls.oneComic(comicHref, random.uniform(0,3)) + #dirConfComic = comicInfo.getDirConfComic() + #if not os.path.exists(dirConfComic): + netUtils.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}") + time.sleep(random_int) + cls.oneComic(comicHref, random.uniform(0,3)) print(books) #for comicHref in comicsHref: @@ -76,7 +76,7 @@ class comicEntity: chapter = chapters[count_chapter] comicInfo.setChapterName(chapter) if not comicInfo.nextExistsGetPath("done_"): - comicEntity.comicChapter(href,scramble=True,sleep=random.uniform(15,25)) + comicEntity.comicChapter(href,scramble=True,sleep=random.randint(15,25)) count_chapter += 1 #一本漫画下载后等待 #清空文件夹 @@ -106,14 +106,14 @@ class comicEntity: #完成删除原文件 remove_path = comicInfo.getDirComicChapter() shutil.rmtree(remove_path) - print(f"文件已删除: {remove_path}") + netUtils.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: - print(f"{sleep} 秒后开始下载下一个章节") + netUtils.sendMsg(f"{sleep} 秒后开始下载下一个章节") time.sleep(sleep) @classmethod @@ -149,6 +149,7 @@ class comicEntity: description = x.get("description") images = x.get("images") chapterAPIPath = x.get("chapterAPIPath") + netUtils.sendMsg(f"{bookName} {chapterName} 下载中") comicInfo.setComicName(bookName) comicInfo.setChapterName(chapterName) comicInfo.setDep(description) @@ -165,7 +166,7 @@ class comicEntity: chapterName = data.get("name") images = data.get("images") if images == None: - print(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}") + netUtils.sendMsg(f"未获取到章节图像 comic_name={bookName} chapter={chapterName}") totalChapter = x.get("totalChapter") tags = x.get("tags") x = tags From 99b2dabd1ddc2c03b6aaafb797a07d0a485f8b72 Mon Sep 17 00:00:00 2001 From: cwx Date: Tue, 13 Dec 2022 00:24:45 +0800 Subject: [PATCH 2/6] fix ntfy --- utils/CBZUtils.py | 3 ++- utils/HtmlUtils.py | 9 +++++---- utils/NetUtils.py | 8 +------- utils/Ntfy.py | 8 ++++++++ utils/downloader.py | 5 +++-- utils/entity/RouMan.py | 11 ++++++----- 6 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 utils/Ntfy.py diff --git a/utils/CBZUtils.py b/utils/CBZUtils.py index 05190fe..b76a496 100644 --- a/utils/CBZUtils.py +++ b/utils/CBZUtils.py @@ -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 diff --git a/utils/HtmlUtils.py b/utils/HtmlUtils.py index f3ad62f..58a8fad 100644 --- a/utils/HtmlUtils.py +++ b/utils/HtmlUtils.py @@ -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) diff --git a/utils/NetUtils.py b/utils/NetUtils.py index 967d461..f8f6383 100644 --- a/utils/NetUtils.py +++ b/utils/NetUtils.py @@ -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')) \ No newline at end of file + comicInfo.nextDownloadToCBZChapter() \ No newline at end of file diff --git a/utils/Ntfy.py b/utils/Ntfy.py new file mode 100644 index 0000000..9f526df --- /dev/null +++ b/utils/Ntfy.py @@ -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')) \ No newline at end of file diff --git a/utils/downloader.py b/utils/downloader.py index fb454df..ec9fd9c 100644 --- a/utils/downloader.py +++ b/utils/downloader.py @@ -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: diff --git a/utils/entity/RouMan.py b/utils/entity/RouMan.py index 4987c8e..a43d3a4 100644 --- a/utils/entity/RouMan.py +++ b/utils/entity/RouMan.py @@ -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 From cdc3f2d8c6e63f0e7475105f86c360b267197e0b Mon Sep 17 00:00:00 2001 From: cwx Date: Tue, 13 Dec 2022 00:26:56 +0800 Subject: [PATCH 3/6] fix ntfy --- utils/HtmlUtils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/HtmlUtils.py b/utils/HtmlUtils.py index 58a8fad..d2458d2 100644 --- a/utils/HtmlUtils.py +++ b/utils/HtmlUtils.py @@ -28,7 +28,7 @@ class htmlUtils: while url_text == None: if count <= 10: try: - ntfy.sendMsg(f"请求地址:{curl}") + print(f"请求地址:{curl}") res = s.get(curl,stream=True, headers=cls.headers, timeout=50) if type == "bytes": url_text = res From 403ca9fbf703ab8aab976dd7a58d2734a0d76d30 Mon Sep 17 00:00:00 2001 From: cwx Date: Tue, 13 Dec 2022 00:37:49 +0800 Subject: [PATCH 4/6] fix --- utils/CBZUtils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/CBZUtils.py b/utils/CBZUtils.py index b76a496..28812df 100644 --- a/utils/CBZUtils.py +++ b/utils/CBZUtils.py @@ -36,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() - ntfy.sendMsg("打包完成:", target_file) + ntfy.sendMsg(f"打包完成:{target_file}") #md5_file = md5(target_file) #print("md5:", md5_file) #msg[target_file] = md5_file From c80b9e378d36af5dc72f291ecef20729eef4dfbb Mon Sep 17 00:00:00 2001 From: cwx Date: Tue, 13 Dec 2022 00:40:48 +0800 Subject: [PATCH 5/6] fix --- utils/entity/RouMan.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/utils/entity/RouMan.py b/utils/entity/RouMan.py index a43d3a4..1a536c5 100644 --- a/utils/entity/RouMan.py +++ b/utils/entity/RouMan.py @@ -32,10 +32,12 @@ class comicEntity: comicHref = baseUrl+"/books/"+book_id random_int = random.randint(5,20) comicInfo.setComicName(book_name) - #dirConfComic = comicInfo.getDirConfComic() - #if not os.path.exists(dirConfComic): - ntfy.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}") - time.sleep(random_int) + dirConfComic = comicInfo.getDirConfComic() + if not os.path.exists(dirConfComic): + ntfy.sendMsg(f"{random_int}秒后开始下载 漫画:{book_name}") + time.sleep(random_int) + else: + ntfy.sendMsg(f"已存在 漫画:{book_name}") cls.oneComic(comicHref, random.uniform(0,3)) print(books) From c93d19c614899c458ce9f78e337d03c11805d2aa Mon Sep 17 00:00:00 2001 From: cwx Date: Tue, 13 Dec 2022 00:56:43 +0800 Subject: [PATCH 6/6] fix --- utils/entity/RouMan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/entity/RouMan.py b/utils/entity/RouMan.py index 1a536c5..11ec8ff 100644 --- a/utils/entity/RouMan.py +++ b/utils/entity/RouMan.py @@ -109,7 +109,7 @@ class comicEntity: #完成删除原文件 remove_path = comicInfo.getDirComicChapter() shutil.rmtree(remove_path) - ntfy.sendMsg(f"文件已删除: {remove_path}") + print(f"文件已删除: {remove_path}") except: dirComicChapter = comicInfo.getDirComicChapter if not dirComicChapter == None and os.path.exists(dirComicChapter):