Current status
This commit is contained in:
commit
b8a4e17b8c
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
settings.ini
|
||||
*.pyc
|
||||
__pycache__/
|
||||
venv/
|
30
application.py
Normal file
30
application.py
Normal file
|
@ -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()
|
1
classes/__init__.py
Normal file
1
classes/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
from .config import Config
|
27
classes/config.py
Normal file
27
classes/config.py
Normal file
|
@ -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)
|
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
gotify
|
2
settings.dist.ini
Normal file
2
settings.dist.ini
Normal file
|
@ -0,0 +1,2 @@
|
|||
GotifyURL = https://gotify.lan/
|
||||
Token = adfjkldfjkdfj
|
Loading…
Reference in a new issue