improved einsatzrapport handling

This commit is contained in:
Tobias Brunner 2019-11-03 13:22:47 +01:00
parent f2595ea604
commit b0803a6d86
3 changed files with 38 additions and 14 deletions

View File

@ -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)

View File

@ -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 """

19
main.py
View File

@ -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",