BW3-Core/boswatch/utils/wildcard.py

56 lines
1.5 KiB
Python
Raw Normal View History

2018-01-15 21:45:58 +01:00
#!/usr/bin/python
2018-01-15 14:18:15 +01:00
# -*- coding: utf-8 -*-
"""!
____ ____ ______ __ __ __ _____
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
German BOS Information Script
by Bastian Schroll
@file: wildcard.py
@date: 15.01.2018
@author: Bastian Schroll
@description: Little Helper to replace wildcards in stings
2018-01-15 21:00:52 +01:00
@todo not completed yet
2018-01-15 14:18:15 +01:00
"""
import logging
# from boswatch.module import file
logging.debug("- %s loaded", __name__)
2018-02-01 14:41:09 +01:00
# todo insert all wildcards and delete testcode under the function
2018-01-15 14:18:15 +01:00
2018-02-01 14:41:09 +01:00
def replaceWildcards(message): #, bwPacket):
_wildcards = {
# formatting wildcards
"%BR%": "\r\n",
"%LPAR%": "(",
"%RPAR%": ")",
2018-01-15 14:18:15 +01:00
2018-02-01 14:41:09 +01:00
# boswatch wildcards
"%MODE%": "",# bwPacket.getField("mode"),
"%FREQ% ": "",# bwPacket.getField("frequency")
2018-01-15 14:18:15 +01:00
2018-02-01 14:41:09 +01:00
# fms wildcards
# pocsag wildcards
# zvei wildcards
}
message.replace("nett", "test")
for wildcard in _wildcards:
try:
message = message.replace(wildcard, _wildcards[wildcard])
except:
logging.exception("error in wildcard replacement")
return message
ttext = "das ist ein test %BR% der echt gut %TEST% ist weil %LPAR% er es ust."
print(ttext)
print(replaceWildcards(ttext))