Enhance securecad message parsing to handle additional table structures for 'Einsatzziel', 'Zusatztext zum Ort', and 'Zusatztext zum Objekt'
This commit is contained in:
parent
399d8e498d
commit
883fc84c02
@ -5,8 +5,10 @@ from numpy import nan
|
|||||||
tt_list_alarmdepesche = []
|
tt_list_alarmdepesche = []
|
||||||
tt_list_infodepesche = []
|
tt_list_infodepesche = []
|
||||||
tt_list_einsatzprotokoll = []
|
tt_list_einsatzprotokoll = []
|
||||||
|
|
||||||
def parse_securecad_message(body_html: str):
|
def parse_securecad_message(body_html: str):
|
||||||
body_html = body_html.replace(u'\xa0', u' ')
|
body_html = body_html.replace(u'\xa0', u' ')
|
||||||
|
|
||||||
if 'ALARMDEPESCHE' in body_html:
|
if 'ALARMDEPESCHE' in body_html:
|
||||||
t_list = {}
|
t_list = {}
|
||||||
tables = pd.read_html(body_html) # Returns list of all tables on page
|
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:
|
for r in table_dict:
|
||||||
if table_dict[r][0] is not nan:
|
if table_dict[r][0] is not nan:
|
||||||
t_list[table_dict[r][0].strip(' :')] = table_dict[r][1]
|
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:
|
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'] = {}
|
t_list['Einsatzziel'] = {}
|
||||||
for r in table_dict:
|
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]
|
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:
|
elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Einsatzziel' and 'Einsatzziel' in t_list:
|
||||||
continue
|
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:
|
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'] = []
|
t_list['Zusatztext zum Ort'] = []
|
||||||
for r in table_dict:
|
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])
|
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:
|
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
|
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:
|
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'] = []
|
t_list['Zusatztext zum Objekt'] = []
|
||||||
for r in table_dict:
|
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])
|
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:
|
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
|
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':
|
elif t_count > 3 and table_dict[0] is not nan and table_dict[0][0] == 'Einsatzmittelliste':
|
||||||
# es folgt die Einsatzmittelliste
|
# es folgt die Einsatzmittelliste
|
||||||
continue
|
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'] = []
|
t_list['Einsatzmittelliste'] = []
|
||||||
for r in table_dict:
|
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({
|
t_list['Einsatzmittelliste'].append({
|
||||||
'Ressourcen': table_dict[r][0] if table_dict[r][0] is not nan else "",
|
'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 "",
|
'Typ': table_dict[r][1] if table_dict[r][1] is not nan else "",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user