Files
Auto_Bangumi/backend/src/module/notification/plugin/bark.py
2023-06-28 16:15:17 +08:00

29 lines
941 B
Python

import logging
from module.network import RequestContent
from module.models import Notification
logger = logging.getLogger(__name__)
class BarkNotification(RequestContent):
def __init__(self, token, **kwargs):
super().__init__()
self.token = token
self.notification_url = "https://api.day.app/push"
@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