2024-07-07 10:33:52 +00:00
|
|
|
REGEX = r"SDS_ILS_BEGINN(#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*)(.*) \$GPSN(.*)E(.*)SDS_ILS_ENDE"
|
|
|
|
|
|
|
|
import os
|
|
|
|
import PyPDF2
|
|
|
|
import re
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from geopy.geocoders import Nominatim
|
2024-07-26 22:42:50 +00:00
|
|
|
from logger import logging
|
2024-07-07 10:33:52 +00:00
|
|
|
|
|
|
|
load_dotenv(override=True)
|
|
|
|
|
|
|
|
DRAEGER_API_KEY = os.environ.get("DRAEGER_API_KEY", default=None)
|
|
|
|
|
|
|
|
def get_city(lat, lon):
|
|
|
|
app = Nominatim(user_agent="Test")
|
|
|
|
location = app.reverse(query="N" + lat[:2] + '.' + lat[2:] + ", E" + lon[:2] + '.' + lon[2:], namedetails=True)
|
|
|
|
|
|
|
|
return [location.raw.get("address").get("postcode"), location.raw.get("address").get("city"), location.raw.get("address").get("city_district")]
|
|
|
|
|
|
|
|
def read_pdf(file_path):
|
|
|
|
with open(file_path, 'rb') as file:
|
|
|
|
reader = PyPDF2.PdfReader(file)
|
|
|
|
text = ''
|
|
|
|
for page in reader.pages:
|
|
|
|
text += page.extract_text()
|
|
|
|
|
|
|
|
return text
|
|
|
|
|
|
|
|
def get_draeger_json(text):
|
|
|
|
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["alertingKeywordText"] = match[0][1] + " " + 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:
|
2024-07-26 22:42:50 +00:00
|
|
|
logging.error(f'Fehler: {e}')
|
2024-07-07 10:33:52 +00:00
|
|
|
|
|
|
|
data["lat"] = match[0][7][:2] + '.' + match[0][7][2:]
|
|
|
|
data["lon"] = match[0][8][:2] + '.' + match[0][8][2:]
|
|
|
|
|
2024-07-26 22:42:50 +00:00
|
|
|
logging.debug(data)
|
2024-07-07 10:33:52 +00:00
|
|
|
return data
|
|
|
|
else:
|
|
|
|
return None
|