mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-02-11 14:27:04 +08:00
Merge pull request #312 from jiangyuyi/notify_title
change: 增加通知标题| add notify title
This commit is contained in:
@@ -28,6 +28,7 @@ class Notification(BaseModel):
|
||||
official_title: str = Field(..., alias="official_title", title="番剧名")
|
||||
season: int = Field(..., alias="season", title="番剧季度")
|
||||
episode: int = Field(..., alias="episode", title="番剧集数")
|
||||
poster_path: str | None = Field(None, alias="poster_path", title="番剧海报路径")
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -32,24 +32,25 @@ class PostNotification:
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _gen_message(notify: Notification) -> str:
|
||||
def _get_poster(notify: Notification):
|
||||
with BangumiDatabase() as db:
|
||||
poster_path = db.match_poster(notify.official_title)
|
||||
if poster_path:
|
||||
poster_link = "https://mikanani.me" + poster_path
|
||||
text = f"""
|
||||
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{poster_link}\n
|
||||
"""
|
||||
# text = f"""
|
||||
# 番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{poster_link}\n
|
||||
# """
|
||||
else:
|
||||
text = f"""
|
||||
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n
|
||||
"""
|
||||
return text
|
||||
poster_link = "https://mikanani.me"
|
||||
# text = f"""
|
||||
# 番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n
|
||||
# """
|
||||
notify.poster_path = poster_link
|
||||
|
||||
def send_msg(self, notify: Notification) -> bool:
|
||||
text = self._gen_message(notify)
|
||||
self._get_poster(notify)
|
||||
try:
|
||||
self.notifier.post_msg(text)
|
||||
self.notifier.post_msg(notify)
|
||||
logger.debug(f"Send notification: {notify.official_title}")
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to send notification: {e}")
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import logging
|
||||
|
||||
from module.network import RequestContent
|
||||
from module.models import Notification
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -11,8 +13,16 @@ class BarkNotification(RequestContent):
|
||||
self.token = token
|
||||
self.notification_url = "https://api.day.app/push"
|
||||
|
||||
def post_msg(self, text) -> bool:
|
||||
data = {"title": "AutoBangumi 番剧更新", "body": text, "device_key": self.token}
|
||||
@staticmethod
|
||||
def gen_message(notify: Notification) -> str:
|
||||
text = f"""
|
||||
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{notify.poster_path}\n
|
||||
"""
|
||||
return text
|
||||
|
||||
def post_msg(self, notify: Notification) -> bool:
|
||||
text = self.gen_message(notify)
|
||||
data = {"title": notify.official_title, "body": text, "device_key": self.token}
|
||||
resp = self.post_data(self.notification_url, data)
|
||||
logger.debug(f"Bark notification: {resp.status_code}")
|
||||
return resp.status_code == 200
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
from module.network import RequestContent
|
||||
from module.models import Notification
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -12,9 +13,17 @@ class ServerChanNotification(RequestContent):
|
||||
super().__init__()
|
||||
self.notification_url = f"https://sctapi.ftqq.com/{token}.send"
|
||||
|
||||
def post_msg(self, text: str) -> bool:
|
||||
@staticmethod
|
||||
def gen_message(notify: Notification) -> str:
|
||||
text = f"""
|
||||
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{notify.poster_path}\n
|
||||
"""
|
||||
return text
|
||||
|
||||
def post_msg(self, notify: Notification) -> bool:
|
||||
text = self.gen_message(notify)
|
||||
data = {
|
||||
"title": "AutoBangumi 番剧更新",
|
||||
"title": notify.official_title,
|
||||
"desp": text,
|
||||
}
|
||||
resp = self.post_data(self.notification_url, data)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
from module.network import RequestContent
|
||||
from module.models import Notification
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -11,8 +12,16 @@ class SlackNotification(RequestContent):
|
||||
self.token = token
|
||||
self.notification_url = "https://api.day.app/push"
|
||||
|
||||
def post_msg(self, text) -> bool:
|
||||
data = {"title": "AutoBangumi 番剧更新", "body": text, "device_key": self.token}
|
||||
@staticmethod
|
||||
def gen_message(notify: Notification) -> str:
|
||||
text = f"""
|
||||
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{notify.poster_path}\n
|
||||
"""
|
||||
return text
|
||||
|
||||
def post_msg(self, notify: Notification) -> bool:
|
||||
text = self.gen_message(notify)
|
||||
data = {"title": notify.official_title, "body": text, "device_key": self.token}
|
||||
resp = self.post_data(self.notification_url, data)
|
||||
logger.debug(f"Bark notification: {resp.status_code}")
|
||||
return resp.status_code == 200
|
||||
@@ -1,6 +1,7 @@
|
||||
import logging
|
||||
|
||||
from module.network.request_contents import RequestContent
|
||||
from module.network import RequestContent
|
||||
from module.models import Notification
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -11,7 +12,15 @@ class TelegramNotification(RequestContent):
|
||||
self.notification_url = f"https://api.telegram.org/bot{token}/sendMessage"
|
||||
self.chat_id = chat_id
|
||||
|
||||
def post_msg(self, text: str) -> bool:
|
||||
@staticmethod
|
||||
def gen_message(notify: Notification) -> str:
|
||||
text = f"""
|
||||
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{notify.poster_path}\n
|
||||
"""
|
||||
return text
|
||||
|
||||
def post_msg(self, notify: Notification) -> bool:
|
||||
text = self.gen_message(notify)
|
||||
data = {
|
||||
"chat_id": self.chat_id,
|
||||
"text": text,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import logging
|
||||
|
||||
from module.network import RequestContent
|
||||
from module.models import Notification
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -13,21 +15,26 @@ class WecomNotification(RequestContent):
|
||||
self.notification_url = f"{chat_id}"
|
||||
self.token = token
|
||||
|
||||
def post_msg(self, text: str) -> bool:
|
||||
@staticmethod
|
||||
def gen_message(notify: Notification) -> str:
|
||||
text = f"""
|
||||
番剧名称:{notify.official_title}\n季度: 第{notify.season}季\n更新集数: 第{notify.episode}集\n{notify.poster_path}\n
|
||||
"""
|
||||
return text
|
||||
|
||||
def post_msg(self, notify: Notification) -> bool:
|
||||
##Change message format to match Wecom push better
|
||||
info = text.split(":")
|
||||
print(info)
|
||||
title = "【番剧更新】" + info[1].split("\n")[0].strip()
|
||||
msg = info[2].split("\n")[0].strip()+" "+info[3].split("\n")[0].strip()
|
||||
picurl = info[3].split("\n")[1].strip()
|
||||
title = "【番剧更新】" + notify.official_title
|
||||
msg = self.gen_message(notify)
|
||||
picurl = notify.poster_path
|
||||
#Default pic to avoid blank in message. Resolution:1068*455
|
||||
if picurl == "":
|
||||
if picurl == "https://mikanani.me":
|
||||
picurl = "https://article.biliimg.com/bfs/article/d8bcd0408bf32594fd82f27de7d2c685829d1b2e.png"
|
||||
data = {
|
||||
"key":self.token,
|
||||
"type": "news",
|
||||
"title": title,
|
||||
"msg": msg,
|
||||
"key":self.token,
|
||||
"type": "news",
|
||||
"title": title,
|
||||
"msg": msg,
|
||||
"picurl":picurl
|
||||
}
|
||||
resp = self.post_data(self.notification_url, data)
|
||||
|
||||
Reference in New Issue
Block a user