Merge pull request #237 from Kasper4649/3.0-dev

Add Bark Notification
This commit is contained in:
Estrella Pan
2023-05-06 00:20:39 +08:00
committed by GitHub
2 changed files with 22 additions and 3 deletions

View File

@@ -38,7 +38,7 @@ class RepathTorrents:
season = int(re.search(r"\d{1,2}", season_folder).group())
return season, folder_name
def get_rule(self) -> [RuleInfo]:
def get_rule(self) -> list[RuleInfo]:
rules = self._client.get_download_rules()
all_rule = []
for rule in rules:
@@ -50,7 +50,7 @@ class RepathTorrents:
return all_rule
@staticmethod
def get_difference(bangumi_data: list, rules: [RuleInfo]) -> [RuleInfo]:
def get_difference(bangumi_data: list, rules: list[RuleInfo]) -> list[RuleInfo]:
different_data = []
for data in bangumi_data:
for rule in rules:
@@ -62,7 +62,7 @@ class RepathTorrents:
break
return different_data
def get_matched_torrents_list(self, repath_rules: [RuleInfo]) -> [RePathInfo]:
def get_matched_torrents_list(self, repath_rules: list[RuleInfo]) -> list[RepathInfo]:
infos = self._client.get_torrent_info()
repath_list = []
for rule in repath_rules:

View File

@@ -17,6 +17,8 @@ class PostNotification:
return TelegramNotification()
elif settings.notification.type.lower() == "server-chan":
return ServerChanNotification()
elif settings.notification.type.lower() == "bark":
return BarkNotification()
else:
return None
@@ -61,3 +63,20 @@ class ServerChanNotification:
resp = req.post_data(self.notification_url, data)
logger.debug(f"ServerChan notification: {resp.status_code}")
return resp.status_code == 200
class BarkNotification:
def __init__(self):
self.token = settings.notification.token
self.notification_url = "https://api.day.app/push"
def send_msg(self, title: str, desp: str):
data = {
"title": title,
"body": desp,
"device_key": self.token
}
with RequestContent() as req:
resp = req.post_data(self.notification_url, data)
logger.debug(f"Bark notification: {resp.status_code}")
return resp.status_code == 200