Enhance securecad message parsing to handle additional table structures for 'Einsatzziel', 'Zusatztext zum Ort', and 'Zusatztext zum Objekt'

This commit is contained in:
Simon Zeyer 2026-08-09 11:10:07 +00:00
parent 399d8e498d
commit 883fc84c02

View File

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