From fe6c77830b14d21315b276734ea0fc3b142d588a Mon Sep 17 00:00:00 2001 From: jblu Date: Tue, 16 May 2023 17:22:26 -0500 Subject: [PATCH] updated to take environment files --- Dockerfile | 2 +- apprise-client.py | 39 +++++++++++++++++++++++++++++---------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index ef7b0bd..486d732 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM python:alpine3.18 WORKDIR / ADD https://git.jbranan.com/jblu/apprise-client/raw/branch/main/apprise-client.py opt -ENV toml_path='' +ENV DOCKER=true RUN pip install requests CMD [ "python", "opt/apprise-client.py" ] \ No newline at end of file diff --git a/apprise-client.py b/apprise-client.py index 5a570e1..f4d821f 100644 --- a/apprise-client.py +++ b/apprise-client.py @@ -2,20 +2,39 @@ import requests as r from tomllib import load import os -if os.environ["toml_path"]: - config_file_path=os.environ["toml_path"] -else: - config_file_path = './config.toml' - -with open(config_file_path, 'rb') as c: - config = load(c) - 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__": - a = apprise_notify(r,config["apprise"]["host"],config["apprise"]["port"],config["apprise"]["aurls"],\ - config["apprise"]["title"],config["apprise"]["body"]) \ No newline at end of file + AppriseClient() \ No newline at end of file