From b0803a6d86f8407adbc87ea4b5f3c1e2223e55aa Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Sun, 3 Nov 2019 13:22:47 +0100 Subject: [PATCH] improved einsatzrapport handling --- library/emailhandling.py | 4 ++-- library/lodur.py | 29 +++++++++++++++++++++++++++++ main.py | 19 +++++++------------ 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/library/emailhandling.py b/library/emailhandling.py index 41d11b6..0cf5a55 100644 --- a/library/emailhandling.py +++ b/library/emailhandling.py @@ -9,7 +9,7 @@ import email import email.parser import imaplib -_EMAIL_SUBJECTS = '(OR OR SUBJECT "Einsatzausdruck_FW" SUBJECT "Einsatzprotokoll" SUBJECT "Attached Image" UNSEEN)' +_EMAIL_SUBJECTS = '(OR OR SUBJECT "Einsatzausdruck_FW" SUBJECT "Einsatzprotokoll" SUBJECT "Einsatzrapport" UNSEEN)' class EmailHandling: """ Email handling """ @@ -103,7 +103,7 @@ class EmailHandling: """ extract f id and type from subject """ # This regex matches the subjects filtered already in IMAP search - parsed = re.search('([a-zA-Z]* ?[a-zA-Z]*):? ?(F[0-9].*)?', subject) + parsed = re.search('([a-zA-Z_]*):? ?(F[0-9].*)?', subject) f_type = parsed.group(1) f_id = parsed.group(2) diff --git a/library/lodur.py b/library/lodur.py index 8a0b4fd..c5a701b 100644 --- a/library/lodur.py +++ b/library/lodur.py @@ -195,6 +195,35 @@ class Lodur: self.browser.submit_selected() self.logger.info('[%s] File uploaded', f_id) + def einsatzrapport_scan(self, f_id, file_path, webdav_client): + """ Prepare Einsatzrapport Scan to be sent to Lodur """ + + # check if data is already sent to lodur - data contains lodur_id + lodur_data = webdav_client.get_lodur_data(f_id) + + if lodur_data: + # einsatz available in Lodur - updating existing entry + self.logger.info('[%s] Lodur data found - updating entry', f_id) + + # Complement existing form data + self.logger.info('[%s] Preparing form data for Einsatzprotokoll', f_id) + lodur_data['ang_sit'] = 'Siehe Alarmdepesche - Einsatzrapport' # 17. Angetroffene Situation + lodur_data['mn'] = 'Siehe Alarmdepesche - Einsatzrapport' # 19. Massnahmen + + # Submit the form + self.submit_form_einsatzrapport(lodur_data) + + # Upload scan to Alarmdepesche + self.einsatzrapport_alarmdepesche( + f_id, + file_path, + webdav_client, + ) + else: + # einsatz not available in Lodur + self.logger.error('[%s] No lodur_id found') + return False + def submit_form_einsatzrapport(self, lodur_data): """ Form in module 36 - Einsatzrapport """ diff --git a/main.py b/main.py index 03418c7..6fe673d 100644 --- a/main.py +++ b/main.py @@ -34,7 +34,7 @@ LODUR_BASE_URL = os.getenv("LODUR_BASE_URL") HEARTBEAT_URL = os.getenv("HEARTBEAT_URL") PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN") PUSHOVER_USER_KEY = os.getenv("PUSHOVER_USER_KEY") -PYLOKID_VERSION = "2.1.0" +PYLOKID_VERSION = "2.1.1" def main(): """ main """ @@ -175,7 +175,7 @@ def main(): f_id, ) - # Update entry in Lodur with parse PDF data + # Update entry in Lodur with parsed PDF data lodur_client.einsatzprotokoll(f_id, pdf_data, webdav_client) # Einsatz finished - publish on pushover @@ -193,24 +193,19 @@ def main(): f_id ) - # This is a scan from the Depot printer - elif f_type == 'Attached Image': + # This is usually a scan from the Depot printer + elif f_type == 'Einsatzrapport': logger.info('[%s] Processing type %s', f_id, f_type) # Attach scan in Lodur if f_id is available if f_id != None: - lodur_data = webdav_client.get_lodur_data(f_id) - if lodur_data: - # Upload scan to Lodur - lodur_client.einsatzrapport_alarmdepesche( - f_id, - os.path.join(TMP_DIR, file_name), - webdav_client, - ) + pdf_file = os.path.join(TMP_DIR, file_name) + lodur_client.einsatzrapport_scan(f_id, pdf_file, webdav_client) logger.info( '[%s] Publishing message on Pushover', f_id ) + pushover.send_message( "Scan {} wurde bearbeitet und in Cloud geladen".format(f_id), title="Feuerwehr Scan bearbeitet",