from flask import Flask, request import os import glob import securecad_parser import datetime from hooks import webhook, alarminator_api, cups_print app = Flask(__name__) def wrapHtml(innerHtml): return ''' Bootstrap demo
''' + innerHtml + '''
''' def getAlarmFiles(): dir_path = os.path.dirname(os.path.realpath(__file__)) dir_path = dir_path + "/alarms" + os.sep a_list = glob.glob(dir_path+"*.html") a_list.sort() return a_list def parseAlarm(f): dir_path = os.path.dirname(os.path.realpath(__file__)) f = dir_path + "/alarms" + os.sep + f with open(f, "r") as o: _r: str = o.read() now = datetime.datetime.now() _r = _r.replace('%DATUM%',now.strftime("%d.%m.%Y")) _r = _r.replace('%UHRZEIT%',now.strftime("%H:%M")) if _r != '': return [securecad_parser.parse_securecad_message(_r),_r] @app.route("/") def root(): file = request.args.get('sendalarm') if file is not None: parsed_body, raw = parseAlarm(file) if parsed_body != None: if 'ALARMDEPESCHE' in parsed_body: webhook(parsed_body) alarminator_api(parsed_body) cups_print(parsed_body,raw) html = '
' i: str files = getAlarmFiles() for f in files: html = html + "
" + os.path.basename(f) + "
" html = html + "
" return wrapHtml(html) app.run(port=5000)