Skip to content

Commit

Permalink
optimized some of he invalid character handling
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Dec 16, 2023
1 parent 060673f commit a47af1c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions apprise/plugins/NotifyAprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a47af1c

Please sign in to comment.