improved einsatzrapport handling
This commit is contained in:
parent
f2595ea604
commit
b0803a6d86
|
@ -9,7 +9,7 @@ import email
|
||||||
import email.parser
|
import email.parser
|
||||||
import imaplib
|
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:
|
class EmailHandling:
|
||||||
""" Email handling """
|
""" Email handling """
|
||||||
|
@ -103,7 +103,7 @@ class EmailHandling:
|
||||||
""" extract f id and type from subject """
|
""" extract f id and type from subject """
|
||||||
|
|
||||||
# This regex matches the subjects filtered already in IMAP search
|
# 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_type = parsed.group(1)
|
||||||
f_id = parsed.group(2)
|
f_id = parsed.group(2)
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,35 @@ class Lodur:
|
||||||
self.browser.submit_selected()
|
self.browser.submit_selected()
|
||||||
self.logger.info('[%s] File uploaded', f_id)
|
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):
|
def submit_form_einsatzrapport(self, lodur_data):
|
||||||
""" Form in module 36 - Einsatzrapport """
|
""" Form in module 36 - Einsatzrapport """
|
||||||
|
|
||||||
|
|
19
main.py
19
main.py
|
@ -34,7 +34,7 @@ LODUR_BASE_URL = os.getenv("LODUR_BASE_URL")
|
||||||
HEARTBEAT_URL = os.getenv("HEARTBEAT_URL")
|
HEARTBEAT_URL = os.getenv("HEARTBEAT_URL")
|
||||||
PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
|
PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
|
||||||
PUSHOVER_USER_KEY = os.getenv("PUSHOVER_USER_KEY")
|
PUSHOVER_USER_KEY = os.getenv("PUSHOVER_USER_KEY")
|
||||||
PYLOKID_VERSION = "2.1.0"
|
PYLOKID_VERSION = "2.1.1"
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
""" main """
|
""" main """
|
||||||
|
@ -175,7 +175,7 @@ def main():
|
||||||
f_id,
|
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)
|
lodur_client.einsatzprotokoll(f_id, pdf_data, webdav_client)
|
||||||
|
|
||||||
# Einsatz finished - publish on pushover
|
# Einsatz finished - publish on pushover
|
||||||
|
@ -193,24 +193,19 @@ def main():
|
||||||
f_id
|
f_id
|
||||||
)
|
)
|
||||||
|
|
||||||
# This is a scan from the Depot printer
|
# This is usually a scan from the Depot printer
|
||||||
elif f_type == 'Attached Image':
|
elif f_type == 'Einsatzrapport':
|
||||||
logger.info('[%s] Processing type %s', f_id, f_type)
|
logger.info('[%s] Processing type %s', f_id, f_type)
|
||||||
|
|
||||||
# Attach scan in Lodur if f_id is available
|
# Attach scan in Lodur if f_id is available
|
||||||
if f_id != None:
|
if f_id != None:
|
||||||
lodur_data = webdav_client.get_lodur_data(f_id)
|
pdf_file = os.path.join(TMP_DIR, file_name)
|
||||||
if lodur_data:
|
lodur_client.einsatzrapport_scan(f_id, pdf_file, webdav_client)
|
||||||
# Upload scan to Lodur
|
|
||||||
lodur_client.einsatzrapport_alarmdepesche(
|
|
||||||
f_id,
|
|
||||||
os.path.join(TMP_DIR, file_name),
|
|
||||||
webdav_client,
|
|
||||||
)
|
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
'[%s] Publishing message on Pushover', f_id
|
'[%s] Publishing message on Pushover', f_id
|
||||||
)
|
)
|
||||||
|
|
||||||
pushover.send_message(
|
pushover.send_message(
|
||||||
"Scan {} wurde bearbeitet und in Cloud geladen".format(f_id),
|
"Scan {} wurde bearbeitet und in Cloud geladen".format(f_id),
|
||||||
title="Feuerwehr Scan bearbeitet",
|
title="Feuerwehr Scan bearbeitet",
|
||||||
|
|
Loading…
Reference in New Issue