From 6037e742ccb7d295cc5795913bfb1824f50973ef Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Sun, 20 Sep 2026 19:08:05 +0100 Subject: [PATCH] Fix mojibake in DX cluster and RBN spot comments where the source uses UTF-8 --- core/utils.py | 10 ++++++++++ providers/spot/dxcluster.py | 3 ++- providers/spot/rbn.py | 3 ++- templates/add_spot.html | 2 +- templates/alerts.html | 2 +- templates/bands.html | 4 ++-- templates/base.html | 10 +++++----- templates/conditions.html | 2 +- templates/map.html | 4 ++-- templates/spots.html | 4 ++-- templates/status.html | 2 +- 11 files changed, 29 insertions(+), 17 deletions(-) diff --git a/core/utils.py b/core/utils.py index 0c232ed..ff498fb 100644 --- a/core/utils.py +++ b/core/utils.py @@ -156,3 +156,13 @@ def get_callsign_object_from_pyhamtools_callinfo(callsign, callinfo): except (KeyError, ValueError): # Unknown callsign, can't look anything up, return a Callsign object with basic data so that gets cached return Callsign(call=callsign) + + +def decode_telnet_bytes(data: bytes) -> str: + """Decode a line of text received from a telnet connection, which might be UTF-8 or Latin-1 depending on the + whims of the server owner.""" + + try: + return data.decode("utf-8") + except UnicodeDecodeError: + return data.decode("latin-1") diff --git a/providers/spot/dxcluster.py b/providers/spot/dxcluster.py index 4413207..ed89d57 100644 --- a/providers/spot/dxcluster.py +++ b/providers/spot/dxcluster.py @@ -10,6 +10,7 @@ import telnetlib3 from core.config import SERVER_OWNER_CALLSIGN from data.spot import Spot from providers.spot.spot_provider import SpotProvider +from core.utils import decode_telnet_bytes logger = logging.getLogger(__name__) @@ -96,7 +97,7 @@ class DXCluster(SpotProvider): try: # Check new telnet info against regular expression telnet_output = self._telnet.read_until("\n".encode("latin-1")) - match = self._spot_line_pattern.match(telnet_output.decode("latin-1")) + match = self._spot_line_pattern.match(decode_telnet_bytes(telnet_output)) if match: spot_time = datetime.strptime(match.group(5), "%H%MZ").replace(tzinfo=pytz.UTC) spot_datetime = datetime.combine( diff --git a/providers/spot/rbn.py b/providers/spot/rbn.py index b4f7617..bdfd78e 100644 --- a/providers/spot/rbn.py +++ b/providers/spot/rbn.py @@ -10,6 +10,7 @@ import telnetlib3 from core.config import SERVER_OWNER_CALLSIGN from data.spot import Spot from providers.spot.spot_provider import SpotProvider +from core.utils import decode_telnet_bytes logger = logging.getLogger(__name__) @@ -81,7 +82,7 @@ class RBN(SpotProvider): try: # Check new telnet info against regular expression telnet_output = self._telnet.read_until("\n".encode("latin-1")) - match = self._LINE_PATTERN.match(telnet_output.decode("latin-1")) + match = self._LINE_PATTERN.match(decode_telnet_bytes(telnet_output)) if match: spot_time = datetime.strptime(match.group(5), "%H%MZ").replace(tzinfo=pytz.UTC) spot_datetime = datetime.combine( diff --git a/templates/add_spot.html b/templates/add_spot.html index 8f4d8f1..93066c0 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -77,7 +77,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index 08be530..885f236 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -85,7 +85,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index 4756f26..4d81c6e 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,8 +76,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index f5db8e5..8c917d2 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -16,10 +16,10 @@ window.fetchEventSource = fetchEventSource; - - - - + + + + {% end %} {% block body %}
diff --git a/templates/conditions.html b/templates/conditions.html index 19d80b9..0cfdd8e 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -284,7 +284,7 @@
- + diff --git a/templates/map.html b/templates/map.html index 10f3a6c..dac7020 100644 --- a/templates/map.html +++ b/templates/map.html @@ -113,8 +113,8 @@ const CARTODB_API_KEY = "{{ web_ui_options.get('cartodb_api_key', '') }}"; - - + + diff --git a/templates/spots.html b/templates/spots.html index 4945d3e..89dd07e 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -125,8 +125,8 @@ - - + + diff --git a/templates/status.html b/templates/status.html index 1c1da0e..a8ef30c 100644 --- a/templates/status.html +++ b/templates/status.html @@ -96,7 +96,7 @@ - +