From f53102d8c8ec19efff7cee3c903df7be684dcfa3 Mon Sep 17 00:00:00 2001 From: KoenigMjr <135820716+KoenigMjr@users.noreply.github.com> Date: Mon, 4 Aug 2025 09:36:09 +0200 Subject: [PATCH] =?UTF-8?q?Behebung=20der=20WARNING=20"field=20not=20found?= =?UTF-8?q?"=20im=20Log=20Bedingt=20durch=20die=20modeunabh=C3=A4ngige=20V?= =?UTF-8?q?erarbeitung=20s=C3=A4mtlicher=20Wildcards=20warnt=20das=20Progr?= =?UTF-8?q?amm,=20dass=20manche=20Felder=20nicht=20verf=C3=BCgbar=20sind,?= =?UTF-8?q?=20die=20in=20der=20derzeitigen=20Auswertung=20jedoch=20gar=20n?= =?UTF-8?q?icht=20vorhanden=20sein=20k=C3=B6nnen=20(z.B.=20FMS=20Felder=20?= =?UTF-8?q?in=20ZVEI-Datensatz=20etc.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Änderungen: - Wildcard-Ersetzung in `replaceWildcards()` nach Paketmodus (fms, pocsag, zvei, msg) aufgeteilt - Unnötige Wildcards werden nun abhängig vom Modus nicht mehr verarbeitet - `{MSG}` wird nun explizit für den Modus `msg` unterstützt - Kopfzeile mit aktuellem Änderungsdatum versehen --- boswatch/wildcard.py | 88 ++++++++++++++++++++++++++++---------------- 1 file changed, 56 insertions(+), 32 deletions(-) diff --git a/boswatch/wildcard.py b/boswatch/wildcard.py index b260a51..edda224 100644 --- a/boswatch/wildcard.py +++ b/boswatch/wildcard.py @@ -1,17 +1,17 @@ #!/usr/bin/python # -*- coding: utf-8 -*- r"""! - ____ ____ ______ __ __ __ _____ - / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / + ____ ____ ______ __ __ __ _____ + / __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ / / __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ < / /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ / /_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/ - German BOS Information Script - by Bastian Schroll + German BOS Information Script + by Bastian Schroll -@file: wildcard.py -@date: 15.01.2018 -@author: Bastian Schroll +@file: wildcard.py +@date: 23.07.2025 +@author: Bastian Schroll @description: Functions to replace wildcards in stings """ import logging @@ -19,8 +19,6 @@ import time logging.debug("- %s loaded", __name__) -# todo check function - write an test - _additionalWildcards = {} @@ -42,6 +40,8 @@ def replaceWildcards(message, bwPacket): @param message: Message in which wildcards should be replaced @param bwPacket: bwPacket instance with the replacement information @return Input message with the replaced wildcards""" + + # Start with wildcards that are always available _wildcards = { # formatting wildcards # todo check if br and par are needed - if not also change config @@ -69,34 +69,58 @@ def replaceWildcards(message, bwPacket): "{TIMES}": bwPacket.get("timestamp"), "{FREQ}": bwPacket.get("frequency"), "{MODE}": bwPacket.get("mode"), - - # 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"), - - # pocsag wildcards - "{BIT}": bwPacket.get("bitrate"), - "{RIC}": bwPacket.get("ric"), - "{SRIC}": bwPacket.get("subric"), - "{SRICT}": bwPacket.get("subricText"), - "{MSG}": bwPacket.get("message"), - - # zvei wildcards - "{TONE}": bwPacket.get("tone"), - - # message for MSG packet is done in poc } + + # 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 for wildcard, field in _wildcards.items(): + # Only replace if the field was found in the packet (is not None) if field is not None: message = message.replace(wildcard, field) + # Handle additional, dynamically registered wildcards for wildcard, fieldName in _additionalWildcards.items(): field = bwPacket.get(fieldName) if field is not None: