added apprise support #15
This commit is contained in:
parent
c9fff93fe4
commit
8908315665
40
AppriseClient.py
Normal file
40
AppriseClient.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import requests as r
|
||||||
|
from tomllib import load
|
||||||
|
import os
|
||||||
|
|
||||||
|
def apprise_notify(req_obj, host, port, aurls, title, body):
|
||||||
|
payload = {'urls': aurls,'title': title,'body': body,}
|
||||||
|
url = f'http://{host}:{port}/notify/'
|
||||||
|
apprise_response = req_obj.post(url, json = payload ,verify=False)
|
||||||
|
return apprise_response
|
||||||
|
|
||||||
|
class AppriseClient:
|
||||||
|
def __init__(self):
|
||||||
|
self.config = ''
|
||||||
|
try:
|
||||||
|
if os.environ["DOCKER"]:
|
||||||
|
self.host = os.environ["host"]
|
||||||
|
self.port = os.environ["port"]
|
||||||
|
self.aurls = os.environ["aurls"]
|
||||||
|
self.title = os.environ["title"]
|
||||||
|
self.body = os.environ["body"]
|
||||||
|
if os.environ["toml_path"]:
|
||||||
|
config_file_path=os.environ["toml_path"]
|
||||||
|
with open(config_file_path, 'rb') as c:
|
||||||
|
self.config = load(c)
|
||||||
|
except:
|
||||||
|
KeyError
|
||||||
|
if os.path.exists('./config.toml'):
|
||||||
|
config_file_path = './config.toml'
|
||||||
|
with open(config_file_path, 'rb') as c:
|
||||||
|
self.config = load(c)
|
||||||
|
if self.config:
|
||||||
|
self.host = self.config["apprise"]["host"]
|
||||||
|
self.port = self.config["apprise"]["port"]
|
||||||
|
self.aurls = self.config["apprise"]["aurls"]
|
||||||
|
self.title = self.config["apprise"]["title"]
|
||||||
|
self.body = self.config["apprise"]["body"]
|
||||||
|
self.apprise_response = apprise_notify(r,self.host,self.port,self.aurls,self.title,self.body)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
AppriseClient()
|
12
clogging.py
12
clogging.py
@ -16,11 +16,15 @@ def cont_notify(self):
|
|||||||
if self.use_pushover:
|
if self.use_pushover:
|
||||||
self.poc = self.po.Pushover(self.po_token)
|
self.poc = self.po.Pushover(self.po_token)
|
||||||
|
|
||||||
def cont_notify_summary(self):
|
def cont_notify_summary(self, app_obj, req_obj):
|
||||||
"""Main notification method when the app is used in an automated fashion"""
|
"""Main notification method when the app is used in an automated fashion"""
|
||||||
|
title = "--- crane summary ---"
|
||||||
|
body = f'{self.extm}'
|
||||||
if self.use_pushover:
|
if self.use_pushover:
|
||||||
self.poc.message(self.po_key,f" \
|
#TODO figure out why the flip it thinks its getting 4 pos args
|
||||||
{self.extm}", title="--- crane summary ---")
|
self.poc.message(self.po_key, message=body, title=title)
|
||||||
|
if self.use_apprise:
|
||||||
|
app_obj(req_obj, self.apprise_host, self.apprise_port, self.apprise_aurls, title, body)
|
||||||
|
|
||||||
def list_first_cont(self, index=0):
|
def list_first_cont(self, index=0):
|
||||||
"""Only lists the first torrent"""
|
"""Only lists the first torrent"""
|
||||||
@ -35,4 +39,6 @@ def get_script_runtime(self):
|
|||||||
if self.use_log:
|
if self.use_log:
|
||||||
self.tl.info(f'Execution time: [{elapsed_time}]')
|
self.tl.info(f'Execution time: [{elapsed_time}]')
|
||||||
if self.use_pushover:
|
if self.use_pushover:
|
||||||
|
self.extm = f"Execution time: [{elapsed_time}]"
|
||||||
|
if self.use_apprise:
|
||||||
self.extm = f"Execution time: [{elapsed_time}]"
|
self.extm = f"Execution time: [{elapsed_time}]"
|
18
crane.py
18
crane.py
@ -9,16 +9,17 @@ import logging
|
|||||||
import requests
|
import requests
|
||||||
from tomllib import load
|
from tomllib import load
|
||||||
import os
|
import os
|
||||||
|
from AppriseClient import apprise_notify
|
||||||
|
|
||||||
class Crn:
|
class Crn:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Main object, should be calling functions from qlist.py, qlogging.py and qprocess.py"""
|
"""Main object, should be calling functions from qlist.py, qlogging.py and qprocess.py"""
|
||||||
# Open the config. Needs a json file with the data in config.json.example
|
# Open the config. Needs a json file with the data in config.json.example
|
||||||
self.st = datetime.datetime.now()
|
self.st = datetime.datetime.now()
|
||||||
|
if os.getenv("toml_path"):
|
||||||
config_file_path=os.environ["toml_path"]
|
config_file_path=os.getenv("toml_path")
|
||||||
with open(config_file_path, 'rb') as c:
|
with open(config_file_path, 'rb') as c:
|
||||||
self.config = load(c)
|
self.config = load(c)
|
||||||
if os.path.exists('./config.toml'):
|
if os.path.exists('./config.toml'):
|
||||||
config_file_path = './config.toml'
|
config_file_path = './config.toml'
|
||||||
with open(config_file_path, 'rb') as c:
|
with open(config_file_path, 'rb') as c:
|
||||||
@ -45,6 +46,11 @@ class Crn:
|
|||||||
self.use_pushover = self.config["pushover"]["use_pushover"]
|
self.use_pushover = self.config["pushover"]["use_pushover"]
|
||||||
self.po_key = self.config["pushover"]["po_key"]
|
self.po_key = self.config["pushover"]["po_key"]
|
||||||
self.po_token = self.config["pushover"]["po_token"]
|
self.po_token = self.config["pushover"]["po_token"]
|
||||||
|
#apprise
|
||||||
|
self.use_apprise = self.config["apprise"]["use_apprise"]
|
||||||
|
self.apprise_host = self.config["apprise"]["host"]
|
||||||
|
self.apprise_port = self.config["apprise"]["port"]
|
||||||
|
self.apprise_aurls = self.config["apprise"]["aurls"]
|
||||||
#containers
|
#containers
|
||||||
self.observed_containers = list(self.config["containers"].values())
|
self.observed_containers = list(self.config["containers"].values())
|
||||||
self.container_statuses = ["paused","dead","created","exited","removing","restarting","created"]
|
self.container_statuses = ["paused","dead","created","exited","removing","restarting","created"]
|
||||||
@ -71,7 +77,9 @@ class Crn:
|
|||||||
self.et = datetime.datetime.now()
|
self.et = datetime.datetime.now()
|
||||||
get_script_runtime(self)
|
get_script_runtime(self)
|
||||||
if self.use_pushover:
|
if self.use_pushover:
|
||||||
cont_notify_summary(self)
|
cont_notify_summary(self, apprise_notify, requests)
|
||||||
|
if self.use_apprise:
|
||||||
|
cont_notify_summary(self, apprise_notify, requests)
|
||||||
# Run
|
# Run
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
Crn()
|
Crn()
|
Loading…
x
Reference in New Issue
Block a user