diff --git a/helpers.py b/helpers.py index 4c5f87b..f9dd048 100644 --- a/helpers.py +++ b/helpers.py @@ -1,4 +1,4 @@ -REGEX = r"SDS_ILS_BEGINN\s*(#D#Leitstelle:\s*)(?P\d*)(?Pm|o|i)?(?PRTW|NAW|KTW)? (?PTrauma Gesicht\/|Atemnot Akut|Trauma Extremit|Abdomen Akut|Person droht zu spr|Hilflose Person|\S*|)(?P
\D*)(.*) \$GPS\s*N(.*)E(.*)\s*SDS_ILS_ENDE" +REGEX = r"SDS_ILS_BEGINN\s*(#D#Leitstelle:\s*)(?P\d*)(?Pm|o|i)?(?PRTW|NAW|KTW)? (?PTrauma Gesicht\/|Atemnot Akut|Trauma Extremit|Abdomen Akut|Person droht zu spr|Hilflose Person|\S*|)(?P
\D*)(.*)\s*\$GPS\s*N(.*)E(.*)\s*SDS_ILS_ENDE" import os import PyPDF2 @@ -27,31 +27,39 @@ def read_pdf(file_path): return text def get_draeger_json(text): - match = re.findall(REGEX, text.replace("\n", "")) - - if (len(match) != 0): - data = {} + 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 - if(match[0][1].startswith("9")): # 9 => RD (First Rsponder) - data["alertingKeyword"] = "Wachalarm" - else: - data["alertingKeyword"] = match[0][4] - data["alertingKeywordText"] = match[0][1] + match[0][2] + match[0][3] + " " + match[0][4] - data["street"] = match[0][5] - data["houseNumber"] = match[0][6] - - try: - city = get_city(match[0][7], match[0][8]) - data["city"] = city[0] + " " + city[1] - data["cityDistrict"] = city[2] - except Exception as e: - logging.error(f'Fehler: {e}') - - data["lat"] = match[0][7][:2] + '.' + match[0][7][2:] - data["lon"] = match[0][8][:2] + '.' + match[0][8][2:] - - logging.debug(data) - return data + data["alertingKeyword"] = "WRD" + data["alertingKeywordText"] = "Probealarm" else: - return None \ No newline at end of file + match = re.findall(REGEX, text.replace("\n", "")) + + if (len(match) != 0): + data["apiKey"] = DRAEGER_API_KEY + + if(match[0][1].startswith("9")): # 9 => RD (First Rsponder) + data["alertingKeyword"] = "Wachalarm" + else: + 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] + + try: + city = get_city(match[0][7], match[0][8]) + data["city"] = city[0] + " " + city[1] + data["cityDistrict"] = city[2] + except Exception as e: + logging.error(f'Fehler: {e}') + + 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 \ No newline at end of file diff --git a/main.py b/main.py index ee19cd9..e6d03ac 100644 --- a/main.py +++ b/main.py @@ -60,19 +60,19 @@ def check_email(): f.write(part.get_payload(decode=True)) if filename.endswith('.pdf'): - pdf_text = read_pdf(filepath) - + 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: