mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-01-20 15:20:16 +01:00
add helper.replaceWildcards() to helper.py
This commit is contained in:
parent
f124c4fca5
commit
c94ddfce31
12
README.md
12
README.md
|
|
@ -37,12 +37,12 @@ If you want to code your own Plugin, see Section `Code your own Plugin` at the e
|
|||
|
||||
|Plugin|Function|FMS|ZVEI|POC|
|
||||
|-----|---------|:-:|:--:|:-:|
|
||||
|MySQL|insert data into MySQL database|:thumbsup:|:thumbsup:|:thumbsup:|
|
||||
|httpRequest|send a request with parameter to an URL|:thumbsup:|:thumbsup:|:thumbsup:|
|
||||
|eMail|send Mails with own text|:thumbsup:|:thumbsup:|:thumbsup:|
|
||||
|BosMon|send data to BosMon server|:thumbsup:|:thumbsup:|:thumbsup:|
|
||||
|firEmergency|send data to firEmergency server|:x:|:thumbsup:|:thumbsup:|
|
||||
|jsonSocket|send data as jsonString to a socket server|:thumbsup:|:thumbsup:|:thumbsup:|
|
||||
|MySQL|insert data into MySQL database|:white_check_mark:|:white_check_mark:|:white_check_mark:|
|
||||
|httpRequest|send a request with parameter to an URL|:white_check_mark:|:white_check_mark:|:white_check_mark:|
|
||||
|eMail|send Mails with own text|:white_check_mark:|:white_check_mark:|:white_check_mark:|
|
||||
|BosMon|send data to BosMon server|:white_check_mark:|:white_check_mark:|:white_check_mark:|
|
||||
|firEmergency|send data to firEmergency server|:x:|:white_check_mark:|:white_check_mark:|
|
||||
|jsonSocket|send data as jsonString to a socket server|:white_check_mark:|:white_check_mark:|:white_check_mark:|
|
||||
|
||||
- for more Information to the plugins see `config.ini`
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@
|
|||
|
||||
"""
|
||||
little Helper functions
|
||||
mainly for direct usw in plugins to save code
|
||||
mainly for direct use in plugins to save code
|
||||
|
||||
@author: Bastian Schroll
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import time
|
||||
|
||||
|
||||
|
|
@ -29,3 +30,46 @@ def curtime(format="%d.%m.%Y %H:%M:%S"):
|
|||
except:
|
||||
logging.warning("error in time-format-string")
|
||||
logging.debug("error in time-format-string", exc_info=True)
|
||||
|
||||
|
||||
def replaceWildcards(text,data):
|
||||
"""
|
||||
Replace all official Wildcards with the Information from the data[] var
|
||||
|
||||
@type text: string
|
||||
@param text: Input text with wildcards
|
||||
@type data: map
|
||||
@param data: map of data (structure see interface.txt)
|
||||
|
||||
@return: text with replaced wildcards
|
||||
@exception: Exception if Error at replace
|
||||
"""
|
||||
try:
|
||||
# replace date and time wildcards
|
||||
text = text.replace("%TIME%", curtime("%H:%M:%S")).replace("%DATE%", curtime("%d.%m.%Y"))
|
||||
|
||||
# replace FMS data
|
||||
if "fms" in data: text = text.replace("%FMS%", data["fms"])
|
||||
if "status" in data: text = text.replace("%STATUS%", data["status"])
|
||||
if "direction" in data: text = text.replace("%DIR%", data["direction"])
|
||||
if "directionText" in data: text = text.replace("%DIRT%", data["directionText"])
|
||||
if "tsi" in data: text = text.replace("%TSI%", data["tsi"])
|
||||
|
||||
# replace ZVEI data
|
||||
if "zvei" in data: text = text.replace("%ZVEI%", data["zvei"])
|
||||
|
||||
# replace POC data
|
||||
if "ric" in data: text = text.replace("%RIC%", data["ric"])
|
||||
if "function" in data: text = text.replace("%FUNC%", data["function"])
|
||||
if "functionChar" in data: text = text.replace("%FUNCCHAR%", data["functionChar"])
|
||||
if "msg" in data: text = text.replace("%MSG%", data["msg"])
|
||||
if "bitrate" in data: text = text.replace("%BITRATE%", str(data["bitrate"]))
|
||||
|
||||
# replace description (exists by all)
|
||||
if "description" in data: text = text.replace("%DESCR%", data["description"])
|
||||
|
||||
return text
|
||||
|
||||
except:
|
||||
logging.warning("error wildcard replacement")
|
||||
logging.debug("error wildcard replacement", exc_info=True)
|
||||
|
|
|
|||
Loading…
Reference in a new issue