From 6ab9552341c9b91720bd4623850eb077d59fc265 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Thu, 25 Jul 2019 22:06:50 +0200 Subject: [PATCH] initial support for gotify --- library/mqtt.py | 2 +- main.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/library/mqtt.py b/library/mqtt.py index 18c0bbb..9ecb9e7 100644 --- a/library/mqtt.py +++ b/library/mqtt.py @@ -19,7 +19,7 @@ class MQTTClient: self.mqtt_client.tls_set() self.mqtt_client.connect(server, 8883, 60) self.mqtt_client.loop_start() - self.logger.info('MQTT connection successfull') + self.logger.info('MQTT connection successful') except Exception as err: self.logger.error('MQTT connection failed: %s', str(err)) diff --git a/main.py b/main.py index 227711d..9eeba59 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from dotenv import find_dotenv, load_dotenv from library.emailhandling import EmailHandling from library.lodur import Lodur from library.mqtt import MQTTClient +from library.gotify import GotifyClient from library.pdf_extract import PDFHandling from library.webdav import WebDav @@ -36,7 +37,9 @@ LODUR_USER = os.getenv("LODUR_USER") LODUR_PASSWORD = os.getenv("LODUR_PASSWORD") LODUR_BASE_URL = os.getenv("LODUR_BASE_URL") HEARTBEAT_URL = os.getenv("HEARTBEAT_URL") -PYLOKID_VERSION = "1.1.0" +GOTIFY_URL = os.getenv("GOTIFY_URL") +GOTIFY_TOKEN = os.getenv("GOTIFY_TOKEN") +PYLOKID_VERSION = "1.2.0" def main(): """ main """ @@ -82,6 +85,12 @@ def main(): MQTT_BASE_TOPIC, ) + # Initialize Gotify + gotify_client = GotifyClient( + GOTIFY_URL, + GOTIFY_TOKEN, + ) + # Initialize PDF Parser pdf = PDFHandling() @@ -124,8 +133,9 @@ def main(): f_id, ) - # publish Einsatz on MQTT + # publish Einsatz on MQTT and Gotify mqtt_client.send_message(f_type, f_id, pdf_data, pdf_file) + gotify_client.send_message(f_type, f_id, pdf_data, pdf_file) # create new Einsatzrapport in Lodur lodur_client.einsatzrapport( @@ -163,8 +173,9 @@ def main(): # Update entry in Lodur with parse PDF data lodur_client.einsatzprotokoll(f_id, pdf_data, webdav_client) - # Einsatz finished - publish on MQTT + # Einsatz finished - publish on MQTT and Gotify mqtt_client.send_message(f_type, f_id, pdf_data, pdf_file) + gotify_client.send_message(f_type, f_id, pdf_data, pdf_file) else: logger.error( '[%s] Cannot process Einsatzprotokoll as there is no Lodur ID',