From b8a4e17b8c523e725b16d89bb71c5af98f1bceba Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 26 Aug 2022 13:58:03 +0000 Subject: [PATCH] Current status --- .gitignore | 4 ++++ application.py | 30 ++++++++++++++++++++++++++++++ classes/__init__.py | 1 + classes/config.py | 27 +++++++++++++++++++++++++++ requirements.txt | 1 + settings.dist.ini | 2 ++ 6 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 application.py create mode 100644 classes/__init__.py create mode 100644 classes/config.py create mode 100644 requirements.txt create mode 100644 settings.dist.ini diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8e397 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +settings.ini +*.pyc +__pycache__/ +venv/ \ No newline at end of file diff --git a/application.py b/application.py new file mode 100644 index 0000000..78dd449 --- /dev/null +++ b/application.py @@ -0,0 +1,30 @@ +from urllib.request import Request + +from gotify import Gotify + +from .classes.config import Config + + +def send_message(gotify_url: str, token: str, content: str, title: str = "Webhook", priority: int = 0): + gotify = Gotify( + base_url=gotify_url, + app_token=token, + ) + + gotify.create_message( + content, + title=title, + priority=priority, + ) + + +def application(env, start_response): + config = Config() + + try: + send_message(config.gotify_url, config.token, config.message, config.title, config.priority) + start_response('200 OK', [('Content-Type','text/html')]) + return "200 OK".encode() + except Exception as e: + start_response('500 Internal Server Error') + return "500 Internal Server Error".encode() \ No newline at end of file diff --git a/classes/__init__.py b/classes/__init__.py new file mode 100644 index 0000000..3558f42 --- /dev/null +++ b/classes/__init__.py @@ -0,0 +1 @@ +from .config import Config \ No newline at end of file diff --git a/classes/config.py b/classes/config.py new file mode 100644 index 0000000..bb9ff8f --- /dev/null +++ b/classes/config.py @@ -0,0 +1,27 @@ +from configparser import ConfigParser + + +class Config: + def __init__(self, path="settings.ini"): + self._parser = ConfigParser() + self._parser.read(path) + + @property + def gotify_url(self): + return self._parser.get(self._parser.default_section, "GotifyURL") + + @property + def token(self): + return self._parser.get(self._parser.default_section, "Token") + + @property + def message(self): + return self._parser.get(self._parser.default_section, "Message", fallback="Your Webhook was triggered!") + + @property + def title(self): + return self._parser.get(self._parser.default_section, "Title", fallback="Webhook") + + @property + def priority(self): + return self._parser.getint(self._parser.default_section, "Priority", fallback=0) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..266e733 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +gotify \ No newline at end of file diff --git a/settings.dist.ini b/settings.dist.ini new file mode 100644 index 0000000..a24dadc --- /dev/null +++ b/settings.dist.ini @@ -0,0 +1,2 @@ +GotifyURL = https://gotify.lan/ +Token = adfjkldfjkdfj \ No newline at end of file