From 5ea8ca10909d3d12bf5b426b899b64f5df4eeb2b Mon Sep 17 00:00:00 2001 From: hockeygoalie35 Date: Tue, 23 Apr 2024 23:50:21 -0400 Subject: [PATCH] Initial ntfy and Pushover integration --- lidarr/python/ARLChecker.py | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lidarr/python/ARLChecker.py b/lidarr/python/ARLChecker.py index 3193de1..8ec3896 100644 --- a/lidarr/python/ARLChecker.py +++ b/lidarr/python/ARLChecker.py @@ -216,6 +216,10 @@ class LidarrExtendedAPI: self.log.error(Fore.RED + 'Update the token in extended.conf' + Fore.LIGHTWHITE_EX) if self.telegram_bot_running: # Don't re-start the telegram bot if it's already running after bot invalid token entry return False + if self.enable_pushover_notify: + pushover_notify(self.pushover_app_api_key,self.pushover_user_key,'---\U0001F6A8WARNING\U0001F6A8-----\nARL TOKEN EXPIRED\n Update arlToken in extended.conf"\n You can find a new ARL at:\nhttps://rentry.org/firehawk52#deezer-arls') + if self.enable_ntfy_notify: + ntfy_notify(self.ntfy_topic,'---\U0001F6A8WARNING\U0001F6A8-----\nARL TOKEN EXPIRED\n Update arlToken in extended.conf\n You can find a new ARL at:\n"https://rentry.org/firehawk52#deezer-arls"') if self.enable_telegram_bot: self.log.info(Fore.YELLOW + 'Starting Telegram bot...Check Telegram and follow instructions.' + Fore.LIGHTWHITE_EX) self.telegram_bot_running = True @@ -329,15 +333,27 @@ class TelegramBotControl: return -class PushNotify(): # LidarrExtendedAPI): - def __init__(self): - return - def send_notfication(self): - response = requests.post("https://api.pushover.net/1/messages.json", data={ - "token": "acoz3cosq7kjmriyz1xjk65a4tdsac", - "user": "uspmrejfhbtxkbydfdqbbe3ch2vebp", - "message": "test" - }) +def pushover_notify(api_token,user_key,message): + log = logging.getLogger('ARLChecker') # Get Logging + log.info(Fore.YELLOW + 'Attempting Pushover Notification' + Fore.LIGHTWHITE_EX) + response = requests.post("https://api.pushover.net/1/messages.json", data={ + "token": api_token, + "user": user_key, + "message": message + }) + if response.json()['status'] == 1: + log.info(Fore.GREEN+"Pushover notification sent successfully"+Fore.LIGHTWHITE_EX) + else: + for message_error in response.json()['errors']: + log.error(Fore.RED+f"Pushover Response: {message_error}"+ Fore.LIGHTWHITE_EX) + + +def ntfy_notify(topic_name, message): + log = logging.getLogger('ARLChecker') # Get Logging + log.info(Fore.YELLOW + 'Attempted ntfy Notification' + Fore.LIGHTWHITE_EX) + requests.post(f"https://ntfy.sh/{topic_name}",data=message) + + def check_token(token=None): log = logging.getLogger('ARLChecker')