forked from StuffAnThings/qbit_manage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapprise.py
More file actions
executable file
·35 lines (27 loc) · 1.15 KB
/
apprise.py
File metadata and controls
executable file
·35 lines (27 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""Apprise notification class"""
import time
import requests
from modules import util
from modules.util import Failed
logger = util.logger
class Apprise:
"""Apprise notification class"""
def __init__(self, config, params):
self.config = config
self.api_url = params["api_url"]
logger.secret(self.api_url)
self.notify_url = ",".join(params["notify_url"])
response = self.check_api_url()
time.sleep(1) # Pause for 1 second before sending the next request
if response.status_code != 200:
raise Failed(f"Apprise Error: Unable to connect to Apprise using {self.api_url}")
def check_api_url(self):
"""Check if the API URL is valid"""
# Check the response using application.json get header
status_endpoint = self.api_url + "/status"
try:
response = self.config.get(status_endpoint, headers={"Accept": "application/json"})
response.raise_for_status()
return response
except requests.exceptions.RequestException as e:
raise Failed(f"Apprise Error: Unexpected error connecting to {status_endpoint} ({e})")