handle scans

This commit is contained in:
Tobias Brunner 2019-10-28 21:25:34 +01:00
parent 7d4654ffd1
commit f2595ea604
5 changed files with 39 additions and 7 deletions

View File

@ -37,6 +37,9 @@ pylokid funktioniert so:
diese im Lodur am entsprechenden Einsatzrapport angehängt.
* Ist der Einsatz abgeschlossen und das Einsatzprotokoll eingetroffen
werden die Informationen im Lodur nachgetragen.
* Wird der von Hand ausgefüllte Einsatzrapport via Scanner per E-Mail
an das E-Mail Postfach gesendet (Betreff "Attached Image FXXXXXXXX")
wird das PDF in der Cloud und im Lodur gespeichert.
Desweiteren wird über Pushover eine Nachricht mit möglichst vielen
Informationen publiziert.

View File

@ -9,7 +9,7 @@ import email
import email.parser
import imaplib
_EMAIL_SUBJECTS = '(OR SUBJECT "Einsatzausdruck_FW" SUBJECT "Einsatzprotokoll" UNSEEN)'
_EMAIL_SUBJECTS = '(OR OR SUBJECT "Einsatzausdruck_FW" SUBJECT "Einsatzprotokoll" SUBJECT "Attached Image" UNSEEN)'
class EmailHandling:
""" Email handling """
@ -32,7 +32,7 @@ class EmailHandling:
def search_emails(self):
""" searches for emails matching the configured subject """
self.logger.info('Searching for messages matching the subject')
self.logger.info('Searching for messages matching: %s', _EMAIL_SUBJECTS)
try:
typ, msg_ids = self.imap.search(
None,
@ -102,7 +102,8 @@ class EmailHandling:
def parse_subject(self, subject):
""" extract f id and type from subject """
parsed = re.search('(.*): (F[0-9].*)', subject)
# This regex matches the subjects filtered already in IMAP search
parsed = re.search('([a-zA-Z]* ?[a-zA-Z]*):? ?(F[0-9].*)?', subject)
f_type = parsed.group(1)
f_id = parsed.group(2)

View File

@ -176,7 +176,7 @@ class Lodur:
def einsatzrapport_alarmdepesche(self, f_id, file_path, webdav_client):
""" Upload a file to Alarmdepesche """
self.logger.info('[%s] Submitting Alarmdepesche to Lodur', f_id)
self.logger.info('[%s] Submitting File to Lodur "Alarmdepesche"', f_id)
# Login to lodur
self.login()
@ -193,7 +193,7 @@ class Lodur:
# Submit the form
self.browser.submit_selected()
self.logger.info('[%s] Alarmdepesche submitted', f_id)
self.logger.info('[%s] File uploaded', f_id)
def submit_form_einsatzrapport(self, lodur_data):
""" Form in module 36 - Einsatzrapport """

View File

@ -34,7 +34,11 @@ class WebDav:
""" uploads a file to webdav - checks for existence before doing so """
# upload with webdav
remote_upload_dir = self.webdav_basedir + "/" + str(datetime.now().year) + "/" + f_id
if f_id == None:
remote_upload_dir = self.webdav_basedir + "/Inbox"
else:
remote_upload_dir = self.webdav_basedir + "/" + str(datetime.now().year) + "/" + f_id
self.logger.info('[%s] Uploading file to WebDAV "%s"', f_id, remote_upload_dir)
# create directory if not yet there

26
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.0.0"
PYLOKID_VERSION = "2.1.0"
def main():
""" main """
@ -92,6 +92,8 @@ def main():
for subject in attachments:
f_type, f_id = imap_client.parse_subject(subject)
file_name = attachments[subject]
# Upload file to cloud
webdav_client.upload(file_name, f_id)
# Take actions - depending on the type
@ -191,6 +193,28 @@ def main():
f_id
)
# This is a scan from the Depot printer
elif f_type == 'Attached Image':
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,
)
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",
)
else:
logger.error('[%s] Unknown type: %s', f_id, f_type)