From 883fc84c0254e20743464ebc1119bf3c44abdb3b Mon Sep 17 00:00:00 2001 From: Simon Zeyer Date: Sun, 9 Aug 2026 11:10:07 +0000 Subject: [PATCH] Enhance securecad message parsing to handle additional table structures for 'Einsatzziel', 'Zusatztext zum Ort', and 'Zusatztext zum Objekt' --- app/securecad_parser.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/app/securecad_parser.py b/app/securecad_parser.py index 8efc603..e0fcf44 100644 --- a/app/securecad_parser.py +++ b/app/securecad_parser.py @@ -5,8 +5,10 @@ from numpy import nan tt_list_alarmdepesche = [] tt_list_infodepesche = [] tt_list_einsatzprotokoll = [] + def parse_securecad_message(body_html: str): body_html = body_html.replace(u'\xa0', u' ') + if 'ALARMDEPESCHE' in body_html: t_list = {} tables = pd.read_html(body_html) # Returns list of all tables on page @@ -25,6 +27,7 @@ def parse_securecad_message(body_html: str): for r in table_dict: if table_dict[r][0] is not nan: t_list[table_dict[r][0].strip(' :')] = table_dict[r][1] + #Einsatzziel elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Einsatzziel' and 'Einsatzziel' not in t_list: t_list['Einsatzziel'] = {} for r in table_dict: @@ -32,6 +35,12 @@ def parse_securecad_message(body_html: str): t_list['Einsatzziel'][table_dict[r][0].strip(' :')] = table_dict[r][1] elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Einsatzziel' and 'Einsatzziel' in t_list: continue + elif t_count > 3 and table_dict[0] is not nan and 'Einsatzziel' in t_list and len(t_list['Einsatzziel']) == 0: + #Eigene Tabelle unter 'Einsatzziel' + for r in table_dict: + if table_dict[r][0] is not nan and table_dict[r][0] != 'Einsatzziel': + t_list['Einsatzziel'][table_dict[r][0].strip(' :')] = table_dict[r][1] + #Zusatztext zum Ort elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Zusatztext zum Ort' and 'Zusatztext zum Ort' not in t_list: t_list['Zusatztext zum Ort'] = [] for r in table_dict: @@ -39,6 +48,12 @@ def parse_securecad_message(body_html: str): t_list['Zusatztext zum Ort'].append(table_dict[r][1]) elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Zusatztext zum Ort' and 'Zusatztext zum Ort' in t_list: continue + elif t_count > 3 and table_dict[0] is not nan and 'Zusatztext zum Ort' in t_list and len(t_list['Zusatztext zum Ort']) == 0: + #Eigene Tabelle unter 'Zusatztext zum Ort' + for r in table_dict: + if table_dict[r][0] is not nan and table_dict[r][0] != 'Zusatztext zum Ort': + t_list['Zusatztext zum Ort'].append(table_dict[r][1]) + #Zusatztext zum Objekt elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Zusatztext zum Objekt' and 'Zusatztext zum Objekt' not in t_list: t_list['Zusatztext zum Objekt'] = [] for r in table_dict: @@ -46,13 +61,24 @@ def parse_securecad_message(body_html: str): t_list['Zusatztext zum Objekt'].append(table_dict[r][1]) elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Zusatztext zum Objekt' and 'Zusatztext zum Objekt' in t_list: continue + elif t_count > 3 and table_dict[0] is not nan and 'Zusatztext zum Objekt' in t_list and len(t_list['Zusatztext zum Objekt']) == 0: + #Eigene Tabelle unter 'Zusatztext zum Objekt' + for r in table_dict: + if table_dict[r][0] is not nan and table_dict[r][0] != 'Zusatztext zum Objekt': + t_list['Zusatztext zum Objekt'].append(table_dict[r][1]) elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Einsatzmittelliste': # es folgt die Einsatzmittelliste continue - elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Ressourcen'and table_dict[0][1] == 'Typ' and table_dict[0][2] == 'Organisation': + elif t_count > 3 and table_dict[0] is not nan and len(table_dict)>1 and ( + # In der ersten Zeile steht "Ressourcen, Typ, Organisation" + (table_dict[0][0] == 'Ressourcen'and table_dict[0][1] == 'Typ' and table_dict[0][2] == 'Organisation' ) + or + # In der ersten Zeile steht "Alarmierte Ressourcen", in der zweiten Zeile steht "Ressourcen, Typ, Organisation" + (table_dict[1][0] == 'Ressourcen'and table_dict[1][1] == 'Typ' and table_dict[1][2] == 'Organisation' ) + ): t_list['Einsatzmittelliste'] = [] for r in table_dict: - if table_dict[r][0] != "Ressourcen": + if table_dict[r][0] != "Ressourcen" and table_dict[r][0] != 'Alarmierte Ressourcen': t_list['Einsatzmittelliste'].append({ 'Ressourcen': table_dict[r][0] if table_dict[r][0] is not nan else "", 'Typ': table_dict[r][1] if table_dict[r][1] is not nan else "",