diff --git a/module/core/renamer.py b/module/core/renamer.py index 98d5c2e3..bd31f99e 100644 --- a/module/core/renamer.py +++ b/module/core/renamer.py @@ -8,6 +8,7 @@ from .download_client import DownloadClient from module.conf import settings from module.parser import TitleParser +from ..network import PostNotification, FtqqNotification logger = logging.getLogger(__name__) @@ -53,6 +54,7 @@ class Renamer: return path_name, season, folder_name, suffix, download_path def run(self): + notification = FtqqNotification() recent_info, torrent_count = self.get_torrent_info() rename_count = 0 for info in recent_info: @@ -68,6 +70,7 @@ class Renamer: old_name = info.content_path.replace(info.save_path, "") self.client.rename_torrent_file(torrent_hash, new_name, old_name, new_name) rename_count += 1 + notification.send_msg(f"《{name[:10]}》缓存成功", f"[Auto Bangumi]《{name}》缓存成功") else: continue except Exception as e: diff --git a/module/network/__init__.py b/module/network/__init__.py index 269d54ac..326efdf1 100644 --- a/module/network/__init__.py +++ b/module/network/__init__.py @@ -1,6 +1,2 @@ from .request_contents import RequestContent -from .notification import PostNotification - - - - +from .notification import PostNotification, FtqqNotification diff --git a/module/network/notification.py b/module/network/notification.py index 06086f0b..75dc141c 100644 --- a/module/network/notification.py +++ b/module/network/notification.py @@ -1,8 +1,13 @@ +import logging + import requests from module.conf import settings +logger = logging.getLogger(__name__) + + class PostNotification: def __init__(self): self.token = settings.notification_token @@ -11,4 +16,31 @@ class PostNotification: def ifttt_post(self, message): url = self.notification_url(message) response = requests.get(url) - return response.status_code == 200 \ No newline at end of file + return response.status_code == 200 + + +class FtqqNotification: + """Server酱推送""" + + def __init__(self): + self.token = settings.notification.token + self.notification_url = f"https://sctapi.ftqq.com/{self.token}.send" + + def send_msg(self, title: str, desp: str) -> bool: + data = { + "title": title, + "desp": desp, + } + try: + resp = requests.post(self.notification_url, json=data, timeout=3) + resp.raise_for_status() + except requests.RequestException as e: + logging.error("[FtqqNotification] send fail, error: %s" % e) + return False + return True + + +if __name__ == '__main__': + name = "勇者、辞职不干了" + notification = FtqqNotification() + notification.send_msg(f"《{name[:10]}》缓存成功", f"[Auto Bangumi]《{name}》缓存成功")