增加推送功能

This commit is contained in:
WeijiangChen
2023-03-13 00:17:30 +08:00
parent 3b745969d1
commit e9f493863b
3 changed files with 37 additions and 6 deletions

View File

@@ -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:

View File

@@ -1,6 +1,2 @@
from .request_contents import RequestContent
from .notification import PostNotification
from .notification import PostNotification, FtqqNotification

View File

@@ -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
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}》缓存成功")