From 931b82ff1aaf06a161b0e5059c30165419473119 Mon Sep 17 00:00:00 2001 From: Kasper4649 Date: Fri, 5 May 2023 22:34:12 +0800 Subject: [PATCH 1/4] feat: add bark notification --- src/module/network/notification.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/module/network/notification.py b/src/module/network/notification.py index 993c231b..e1fba4dd 100644 --- a/src/module/network/notification.py +++ b/src/module/network/notification.py @@ -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 From c5246630c5228db1cc1e92e05d667ee44c8dec60 Mon Sep 17 00:00:00 2001 From: Kasper4649 Date: Fri, 5 May 2023 22:34:28 +0800 Subject: [PATCH 2/4] fix type annotation --- src/module/manager/repath.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/module/manager/repath.py b/src/module/manager/repath.py index b53fd4fd..d1a61e73 100644 --- a/src/module/manager/repath.py +++ b/src/module/manager/repath.py @@ -1,5 +1,6 @@ import logging import re +from typing import List from dataclasses import dataclass from pathlib import PurePath, PureWindowsPath @@ -38,7 +39,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 +51,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 +63,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: From f829b4253963fd3ae0ec4ba4c0ebcac9a29a5569 Mon Sep 17 00:00:00 2001 From: Estrella Pan <33726646+EstrellaXD@users.noreply.github.com> Date: Fri, 5 May 2023 23:56:02 +0800 Subject: [PATCH 3/4] Update repath.py In python3.11 use list instead of Typing.List --- src/module/manager/repath.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/module/manager/repath.py b/src/module/manager/repath.py index d1a61e73..955d7e57 100644 --- a/src/module/manager/repath.py +++ b/src/module/manager/repath.py @@ -1,6 +1,5 @@ import logging import re -from typing import List from dataclasses import dataclass from pathlib import PurePath, PureWindowsPath @@ -39,7 +38,7 @@ class RepathTorrents: season = int(re.search(r"\d{1,2}", season_folder).group()) return season, folder_name - def get_rule(self) -> List[RuleInfo]: + def get_rule(self) -> list[RuleInfo]: rules = self._client.get_download_rules() all_rule = [] for rule in rules: @@ -51,7 +50,7 @@ class RepathTorrents: return all_rule @staticmethod - def get_difference(bangumi_data: list, rules: List[RuleInfo]) -> List[RuleInfo]: + def get_difference(bangumi_data: list, rules: List[RuleInfo]) -> list[RuleInfo]: different_data = [] for data in bangumi_data: for rule in rules: From d8bfaa1b527267276e043d0de910290aaab913b5 Mon Sep 17 00:00:00 2001 From: Estrella Pan <33726646+EstrellaXD@users.noreply.github.com> Date: Fri, 5 May 2023 23:57:16 +0800 Subject: [PATCH 4/4] Update repath.py --- src/module/manager/repath.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/module/manager/repath.py b/src/module/manager/repath.py index 955d7e57..c2ee5718 100644 --- a/src/module/manager/repath.py +++ b/src/module/manager/repath.py @@ -50,7 +50,7 @@ class RepathTorrents: return all_rule @staticmethod - def get_difference(bangumi_data: list, rules: List[RuleInfo]) -> list[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: List[RuleInfo]) -> List[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: