Compare commits
2 Commits
4a965a96a4
...
883fc84c02
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
883fc84c02 | ||
|
|
399d8e498d |
2
.env.dev
2
.env.dev
@ -13,3 +13,5 @@ alarminator_token=""
|
||||
alarminator_zvies_use_PEALGRP="False"
|
||||
printer=DEFAULT
|
||||
print_num=0
|
||||
DIVERA_MESSANGER_API_KEY=""
|
||||
DIVERA_ALARMER_API_KEY=""
|
||||
@ -14,6 +14,9 @@ ENV alarminator_zvies_use_PEALGRP="False"
|
||||
ENV print_num=0
|
||||
ENV printer="DEFAULT"
|
||||
ENV REQUESTS_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
|
||||
ENV DIVERA_MESSANGER_API_KEY=""
|
||||
ENV DIVERA_ALARMER_API_KEY=""
|
||||
ENV MAPS_API_KEY=""
|
||||
|
||||
|
||||
COPY *.deb /
|
||||
|
||||
@ -50,6 +50,7 @@ def run():
|
||||
webhook(parsed_body)
|
||||
alarminator_api(parsed_body)
|
||||
cups_print(parsed_body,m.body)
|
||||
divera_messenger(parsed_body)
|
||||
pass
|
||||
|
||||
def folder_event_subscriber(folder: Folder):
|
||||
|
||||
68
app/hooks.py
68
app/hooks.py
@ -6,6 +6,8 @@ from weasyprint import HTML
|
||||
from requests.adapters import Retry
|
||||
import uuid
|
||||
import subprocess
|
||||
import datetime
|
||||
import time
|
||||
|
||||
retries = Retry(total=5,
|
||||
backoff_factor=0.1,
|
||||
@ -152,3 +154,69 @@ def cups_print(parsed_body: dict, body: str):
|
||||
finally:
|
||||
if os.path.exists(fname):
|
||||
os.remove(fname)
|
||||
|
||||
|
||||
def divera_messenger(parsed_body: dict):
|
||||
# /api/v2/alarms
|
||||
# message-channels?accesskey=XXX
|
||||
|
||||
try:
|
||||
api = "https://app.divera247.com/api/v2/"
|
||||
messenger_api_token = os.environ.get('DIVERA_MESSANGER_API_KEY') if os.environ.get('DIVERA_MESSANGER_API_KEY') else ""
|
||||
alarmer_api_token = os.environ.get('DIVERA_ALARMER_API_KEY') if os.environ.get('DIVERA_ALARMER_API_KEY') else ""
|
||||
if messenger_api_token != "":
|
||||
if 'ALARMDEPESCHE' in parsed_body: # sendAlarm triggern
|
||||
if 'Einsatzmittelliste' in parsed_body:
|
||||
|
||||
zveis = []
|
||||
message = "Alarmierte Einsatzmittel:\n"
|
||||
for r in parsed_body['Einsatzmittelliste']:
|
||||
if r['Typ'] == 'PEALGRP':
|
||||
zveis.append(r['Ressourcen'])
|
||||
message +='\n'.join(zveis)
|
||||
if 'Zusatztext zum Ort' in parsed_body:
|
||||
message += "\n\nZusatztext zum Ort:\n"+parsed_body['Zusatztext zum Ort']
|
||||
if 'Zusatztext zum Objekt' in parsed_body:
|
||||
message += "\n\nZusatztext zum Objekt:\n"+parsed_body['Zusatztext zum Objekt']
|
||||
|
||||
logging.info("GET zu {}alarms?accesskey=XXX".format(api))
|
||||
s = requests.Session()
|
||||
s.mount('https://', requests.adapters.HTTPAdapter(max_retries=retries))
|
||||
start = datetime.datetime.now()
|
||||
message_channel_id = None
|
||||
alarm_id = None
|
||||
alarm_text = None
|
||||
while message_channel_id is None and datetime.datetime.now() < start + datetime.timedelta(minutes=1):
|
||||
r = s.get("{}alarms?accesskey={}".format(api, messenger_api_token))
|
||||
r_json = r.json()
|
||||
if 'items' in r_json.get('data',{}):
|
||||
for item in r_json.get('data',{})['items']:
|
||||
if str(r_json['data']['items'][item]['foreign_id']) == str(parsed_body['Auftragsnummer']):
|
||||
logging.info("EinsatzNr {} in Divera gefunden, sende Nachricht...".format(r_json['data']['items'][item]['foreign_id']))
|
||||
message_channel_id = r_json['data']['items'][item]['message_channel_id']
|
||||
alarm_id = r_json['data']['items'][item]['id']
|
||||
alarm_text = r_json['data']['items'][item]['text']
|
||||
if message_channel_id is None or alarm_id is None:
|
||||
time.sleep(20)
|
||||
|
||||
if alarmer_api_token != "":
|
||||
if alarm_text is None:
|
||||
alarm_text = ""
|
||||
r = s.put("{}alarms/{}?accesskey={}".format(api, alarm_id, alarmer_api_token),json={
|
||||
"Alarm": {
|
||||
"text": alarm_text+"\n\n"+message,
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if message_channel_id:
|
||||
r = s.post("{}messages?accesskey={}".format(api, messenger_api_token),json={
|
||||
"Message": {
|
||||
"message_channel_id": str(message_channel_id),
|
||||
# "parent_id": 0,
|
||||
"text": message,
|
||||
}
|
||||
})
|
||||
pass
|
||||
except Exception as e:
|
||||
logging.error("divera_messenger", e)
|
||||
|
||||
@ -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 "",
|
||||
|
||||
@ -21,6 +21,8 @@ services:
|
||||
- alarminator_zvies_use_PEALGRP=${alarminator_zvies_use_PEALGRP}
|
||||
- printer=${printer}
|
||||
- print_num=${print_num}
|
||||
- DIVERA_MESSANGER_API_KEY=${DIVERA_MESSANGER_API_KEY}
|
||||
- DIVERA_ALARMER_API_KEY=${DIVERA_ALARMER_API_KEY}
|
||||
volumes:
|
||||
- ./cups:/etc/cups
|
||||
- ./cupsd.conf.txt:/etc/cups/cupsd.conf
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user