mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-14 10:30:35 +08:00
增加推送功能
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -1,6 +1,2 @@
|
||||
from .request_contents import RequestContent
|
||||
from .notification import PostNotification
|
||||
|
||||
|
||||
|
||||
|
||||
from .notification import PostNotification, FtqqNotification
|
||||
|
||||
@@ -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}》缓存成功")
|
||||
|
||||
Reference in New Issue
Block a user