From a47af1c7e0169eb94ef384de753fc1cd5bc81b97 Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Fri, 15 Dec 2023 22:01:33 -0500 Subject: [PATCH] optimized some of he invalid character handling --- apprise/plugins/NotifyAprs.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/apprise/plugins/NotifyAprs.py b/apprise/plugins/NotifyAprs.py index d9fd5d60f..981c01da1 100644 --- a/apprise/plugins/NotifyAprs.py +++ b/apprise/plugins/NotifyAprs.py @@ -93,6 +93,21 @@ "ROTA": "rotate.aprs2.net", } +# Identify all unsupported characters +APRS_BAD_CHARMAP = { + r"Ä": "Ae", + r"Ö": "Oe", + r"Ü": "Ue", + r"ä": "ae", + r"ö": "oe", + r"ü": "ue", + r"ß": "ss", +} + +# Our compiled mapping of bad characters +APRS_COMPILED_MAP = re.compile( + r'(' + '|'.join(APRS_BAD_CHARMAP.keys()) + r')') + class NotifyAprs(NotifyBase): """ @@ -602,15 +617,9 @@ def send(self, body, title="", notify_type=NotifyType.INFO, **kwargs): # see https://www.aprs.org/doc/APRS101.PDF pg. 71 payload = re.sub("[{}|~]+", "", payload) - # Replace German umlauts payload = ( - payload.replace("Ä", "Ae") - .replace("Ö", "Oe") - .replace("Ü", "Ue") - .replace("ä", "ae") - .replace("ö", "oe") - .replace("ü", "ue") - .replace("ß", "ss") + APRS_COMPILED_MAP.sub( + lambda x: APRS_BAD_CHARMAP[x.group()], payload) ) # Finally, constrain output string to 67 characters as