2018-05-16 11:18:23 +02:00
|
|
|
#!/usr/bin/python
|
2018-01-15 14:18:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-09-19 16:13:23 +02:00
|
|
|
r"""!
|
2025-08-04 09:36:09 +02:00
|
|
|
____ ____ ______ __ __ __ _____
|
|
|
|
|
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
2018-01-15 14:18:15 +01:00
|
|
|
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
|
|
|
|
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
|
|
|
|
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
2025-08-04 09:36:09 +02:00
|
|
|
German BOS Information Script
|
|
|
|
|
by Bastian Schroll
|
2018-01-15 14:18:15 +01:00
|
|
|
|
2025-08-04 09:36:09 +02:00
|
|
|
@file: wildcard.py
|
|
|
|
|
@date: 23.07.2025
|
|
|
|
|
@author: Bastian Schroll
|
2019-10-25 21:58:35 +02:00
|
|
|
@description: Functions to replace wildcards in stings
|
2018-01-15 14:18:15 +01:00
|
|
|
"""
|
|
|
|
|
import logging
|
2018-02-22 13:36:50 +01:00
|
|
|
import time
|
2018-01-15 14:18:15 +01:00
|
|
|
|
|
|
|
|
logging.debug("- %s loaded", __name__)
|
|
|
|
|
|
2019-10-25 21:58:35 +02:00
|
|
|
_additionalWildcards = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def registerWildcard(wildcard, bwPacketField):
|
2023-09-19 16:13:23 +02:00
|
|
|
r"""!Register a new additional wildcard
|
2019-10-26 18:35:31 +02:00
|
|
|
|
|
|
|
|
@param wildcard: New wildcard string with format: '{WILDCARD}'
|
|
|
|
|
@param bwPacketField: Field of the bwPacket which is used for wildcard replacement"""
|
2019-10-25 21:58:35 +02:00
|
|
|
if wildcard in _additionalWildcards:
|
|
|
|
|
logging.error("wildcard always registered: %s", wildcard)
|
|
|
|
|
return
|
|
|
|
|
logging.debug("register new wildcard %s for field: %s", wildcard, bwPacketField)
|
|
|
|
|
_additionalWildcards[wildcard] = bwPacketField
|
2018-01-15 14:18:15 +01:00
|
|
|
|
|
|
|
|
|
2018-02-22 13:36:50 +01:00
|
|
|
def replaceWildcards(message, bwPacket):
|
2023-09-19 16:13:23 +02:00
|
|
|
r"""!Replace the wildcards in a given message
|
2019-10-26 18:35:31 +02:00
|
|
|
|
|
|
|
|
@param message: Message in which wildcards should be replaced
|
|
|
|
|
@param bwPacket: bwPacket instance with the replacement information
|
|
|
|
|
@return Input message with the replaced wildcards"""
|
2025-08-04 09:36:09 +02:00
|
|
|
|
|
|
|
|
# Start with wildcards that are always available
|
2018-02-01 14:41:09 +01:00
|
|
|
_wildcards = {
|
|
|
|
|
# formatting wildcards
|
2019-10-26 13:41:17 +02:00
|
|
|
# todo check if br and par are needed - if not also change config
|
2018-02-22 13:36:50 +01:00
|
|
|
"{BR}": "\r\n",
|
|
|
|
|
"{LPAR}": "(",
|
|
|
|
|
"{RPAR}": ")",
|
2019-10-26 10:18:55 +02:00
|
|
|
"{TIME}": time.strftime("%d.%m.%Y %H:%M:%S"),
|
2018-02-22 13:36:50 +01:00
|
|
|
|
|
|
|
|
# info wildcards
|
2019-03-02 09:15:40 +01:00
|
|
|
# server
|
2020-02-22 23:47:13 +01:00
|
|
|
"{SNAME}": bwPacket.get("serverName"),
|
|
|
|
|
"{SVERS}": bwPacket.get("serverVersion"),
|
|
|
|
|
"{SDATE}": bwPacket.get("serverBuildDate"),
|
|
|
|
|
"{SBRCH}": bwPacket.get("serverBranch"),
|
2019-09-20 13:06:15 +02:00
|
|
|
|
2019-03-02 09:15:40 +01:00
|
|
|
# client
|
2020-02-22 23:47:13 +01:00
|
|
|
"{CNAME}": bwPacket.get("clientName"),
|
|
|
|
|
"{CIP}": bwPacket.get("clientIP"),
|
|
|
|
|
"{CVERS}": bwPacket.get("clientVersion"),
|
|
|
|
|
"{CDATE}": bwPacket.get("clientBuildDate"),
|
|
|
|
|
"{CBRCH}": bwPacket.get("clientBranch"),
|
2018-01-15 14:18:15 +01:00
|
|
|
|
2018-02-01 14:41:09 +01:00
|
|
|
# boswatch wildcards
|
2020-02-24 21:51:19 +01:00
|
|
|
"{INSRC}": bwPacket.get("inputSource"),
|
|
|
|
|
"{TIMES}": bwPacket.get("timestamp"),
|
2020-02-22 23:47:13 +01:00
|
|
|
"{FREQ}": bwPacket.get("frequency"),
|
|
|
|
|
"{MODE}": bwPacket.get("mode"),
|
2018-02-22 13:36:50 +01:00
|
|
|
}
|
2025-08-04 09:36:09 +02:00
|
|
|
|
|
|
|
|
# Get the packet mode to add specific wildcards
|
|
|
|
|
mode = bwPacket.get("mode")
|
|
|
|
|
|
|
|
|
|
# fms wildcards
|
|
|
|
|
if mode == "fms":
|
|
|
|
|
fms_wildcards = {
|
|
|
|
|
"{FMS}": bwPacket.get("fms"),
|
|
|
|
|
"{SERV}": bwPacket.get("service"),
|
|
|
|
|
"{COUNT}": bwPacket.get("country"),
|
|
|
|
|
"{LOC}": bwPacket.get("location"),
|
|
|
|
|
"{VEHC}": bwPacket.get("vehicle"),
|
|
|
|
|
"{STAT}": bwPacket.get("status"),
|
|
|
|
|
"{DIR}": bwPacket.get("direction"),
|
|
|
|
|
"{DIRT}": bwPacket.get("directionText"),
|
|
|
|
|
"{TACI}": bwPacket.get("tacticalInfo"),
|
|
|
|
|
}
|
|
|
|
|
_wildcards.update(fms_wildcards)
|
|
|
|
|
|
|
|
|
|
# pocsag wildcards
|
|
|
|
|
elif mode == "pocsag":
|
|
|
|
|
pocsag_wildcards = {
|
|
|
|
|
"{BIT}": bwPacket.get("bitrate"),
|
|
|
|
|
"{RIC}": bwPacket.get("ric"),
|
|
|
|
|
"{SRIC}": bwPacket.get("subric"),
|
|
|
|
|
"{SRICT}": bwPacket.get("subricText"),
|
|
|
|
|
"{MSG}": bwPacket.get("message"),
|
|
|
|
|
}
|
|
|
|
|
_wildcards.update(pocsag_wildcards)
|
|
|
|
|
|
|
|
|
|
# zvei wildcards
|
|
|
|
|
elif mode == "zvei":
|
|
|
|
|
zvei_wildcards = {
|
|
|
|
|
"{TONE}": bwPacket.get("tone"),
|
|
|
|
|
}
|
|
|
|
|
_wildcards.update(zvei_wildcards)
|
|
|
|
|
|
|
|
|
|
# msg wildcards
|
|
|
|
|
elif mode == "msg":
|
|
|
|
|
msg_wildcards = {
|
|
|
|
|
"{MSG}": bwPacket.get("message"),
|
|
|
|
|
}
|
|
|
|
|
_wildcards.update(msg_wildcards)
|
|
|
|
|
|
|
|
|
|
# Now, replace all collected wildcards
|
2019-10-25 21:58:35 +02:00
|
|
|
for wildcard, field in _wildcards.items():
|
2025-08-04 09:36:09 +02:00
|
|
|
# Only replace if the field was found in the packet (is not None)
|
2020-02-22 23:47:13 +01:00
|
|
|
if field is not None:
|
|
|
|
|
message = message.replace(wildcard, field)
|
2019-10-25 21:58:35 +02:00
|
|
|
|
2025-08-04 09:36:09 +02:00
|
|
|
# Handle additional, dynamically registered wildcards
|
2021-03-13 17:41:25 +01:00
|
|
|
for wildcard, fieldName in _additionalWildcards.items():
|
|
|
|
|
field = bwPacket.get(fieldName)
|
2020-02-22 23:47:13 +01:00
|
|
|
if field is not None:
|
2021-03-13 17:41:25 +01:00
|
|
|
message = message.replace(wildcard, field)
|
2018-02-01 14:41:09 +01:00
|
|
|
|
|
|
|
|
return message
|