Fix Probealarm, use loops "Wachalarm" and "WRD"

This commit is contained in:
Florian Kaiser 2024-09-06 13:34:37 +02:00
parent af43e7e4fa
commit 42e38c4752
2 changed files with 42 additions and 34 deletions

View File

@ -1,4 +1,4 @@
REGEX = r"SDS_ILS_BEGINN\s*(#D#Leitstelle:\s*)(?P<number>\d*)(?P<sonderrechte>m|o|i)?(?P<fzg>RTW|NAW|KTW)? (?P<keyword>Trauma Gesicht\/|Atemnot Akut|Trauma Extremit|Abdomen Akut|Person droht zu spr|Hilflose Person|\S*|)(?P<address>\D*)(.*) \$GPS\s*N(.*)E(.*)\s*SDS_ILS_ENDE"
REGEX = r"SDS_ILS_BEGINN\s*(#D#Leitstelle:\s*)(?P<number>\d*)(?P<sonderrechte>m|o|i)?(?P<fzg>RTW|NAW|KTW)? (?P<keyword>Trauma Gesicht\/|Atemnot Akut|Trauma Extremit|Abdomen Akut|Person droht zu spr|Hilflose Person|\S*|)(?P<address>\D*)(.*)\s*\$GPS\s*N(.*)E(.*)\s*SDS_ILS_ENDE"
import os
import PyPDF2
@ -27,16 +27,24 @@ def read_pdf(file_path):
return text
def get_draeger_json(text):
data = {}
# Probelarm has another sds format (it is too long so the E coordinate is missing)
if ("Probealarm" in text.replace("\n", "")):
data["apiKey"] = DRAEGER_API_KEY
data["alertingKeyword"] = "WRD"
data["alertingKeywordText"] = "Probealarm"
else:
match = re.findall(REGEX, text.replace("\n", ""))
if (len(match) != 0):
data = {}
data["apiKey"] = DRAEGER_API_KEY
if(match[0][1].startswith("9")): # 9 => RD (First Rsponder)
data["alertingKeyword"] = "Wachalarm"
else:
data["alertingKeyword"] = match[0][4]
data["alertingKeyword"] = "WRD"
data["alertingKeywordText"] = match[0][1] + match[0][2] + match[0][3] + " " + match[0][4]
data["street"] = match[0][5]
data["houseNumber"] = match[0][6]
@ -50,8 +58,8 @@ def get_draeger_json(text):
data["lat"] = match[0][7][:2] + '.' + match[0][7][2:]
data["lon"] = match[0][8][:2] + '.' + match[0][8][2:]
else:
return None
logging.debug(data)
return data
else:
return None

14
main.py
View File

@ -61,18 +61,18 @@ def check_email():
if filename.endswith('.pdf'):
pdf_text = read_pdf(filepath)
r = requests.post('https://einsatzmeldesystem.de/ems/inbound/deployment/universal/', json=get_draeger_json(pdf_text))
logging.debug(r.status_code)
logging.debug(r.json())
except Exception as e:
data = {}
data["apiKey"] = DRAEGER_API_KEY
r = requests.post('https://einsatzmeldesystem.de/ems/inbound/deployment/universal/', json=data)
r = requests.get(HEALTHCHECK_URL + "?status=down&msg=Can not parse data. Alarming with empty data&ping=")
logging.debug(r.status_code)
pass
#data = {}
#data["apiKey"] = DRAEGER_API_KEY
#r = requests.post('https://einsatzmeldesystem.de/ems/inbound/deployment/universal/', json=data)
#
#r = requests.get(HEALTHCHECK_URL + "?status=down&msg=Can not parse data. Alarming with empty data&ping=")
#logging.debug(r.status_code)
mail.logout()
except Exception as e: