diff --git a/telnetserver/telnetserver.py b/telnetserver/telnetserver.py index 2f19d20..cfe3c29 100644 --- a/telnetserver/telnetserver.py +++ b/telnetserver/telnetserver.py @@ -4,6 +4,7 @@ import threading from datetime import datetime import pytz +from pyhamtools import callinfo from core.config import SERVER_OWNER_CALLSIGN from core.constants import SOFTWARE_VERSION @@ -12,6 +13,33 @@ from data.spot import Spot logger = logging.getLogger(__name__) +BANNER = ( + """ + == + ==== ##### ##### #### + == == ..### ..### ..### + == ###==######## ###### ####### .####### ###### .### ###### + ==###.. ..###..### ###..###...###. .###..### ###..### .### ###..### + ==###.### .### .###.### .### .### .### .### .### .### .### .####### + == .###.###.### .###.### .### .### ### .### .### .### .### .### .###... + == ...### .####### ..###### ..##### #### #####..###### #####..###### + == .###. .###=.. ...... ..... .... ..... ...... ..... ...... + == %% ... %%%%###== + == %%%%%%%%%%%#####== \r\n""" + + "== ..... ==" + + f"Welcome to Spothole v{SOFTWARE_VERSION}".rjust(56) + + "\r\n" + + "========================" + + f"This server is run by {SERVER_OWNER_CALLSIGN}".rjust(56) +) + +MOTD = ( + "Spothole's telnet server is a new feature and may not work properly in all\r\n" + + "loggers. Please give it a try in your logger of choice and let me know if it\r\n" + + "(or doesn't!) Please note that DXSpider-like commands are not yet supported\r\n" + + "so you are not yet able to filter spots server-side or log in at all." +) + class TelnetServer: """A telnet server designed to provide spots in the same format as DXSpider, for compatibility with desktop loggers.""" @@ -56,15 +84,22 @@ class TelnetServer: logger.debug("Telnet client connected") self._clients.add(writer) - # Print MOTD + # Print banner and MOTD try: - motd = ( - f"Welcome to Spothole v{SOFTWARE_VERSION}.\r\nThis server is run by {SERVER_OWNER_CALLSIGN}.\r\n===\r\n" + text = ( + BANNER + + "\r\n\r\n" + + "================================================================================" + + "\r\n" + + MOTD + + "\r\n" + + "================================================================================" + + "\r\n\r\n" ) - writer.write(motd.encode("ascii")) + writer.write(text.encode("ascii")) await writer.drain() except Exception: - pass + logger.exception("Exception printing telnet motd") # Set up buffer for user input input_buffer = "" @@ -163,12 +198,14 @@ class TelnetServer: @staticmethod def _format_dxspider_spot(spot: Spot) -> str: """Formats a spot into the format DXspider uses: - DX de CALLSIGN: FREQUENCY DX_CALLSIGN COMMENTS TIME_UTC""" + DX de CALLSIGN: FREQUENCY DX_CALLSIGN COMMENTS TIME_UTC. + Always use the base call for the spotter to save space. Everything must align properly to parse in clients, + and everything must be renderable in ASCII.""" - de_call = f"{spot.de_call + ':' if spot.de_call else '???:'!s:<9}" - frequency = f"{(spot.freq / 1000.0):8.1f}" + de_call = f"{callinfo.Callinfo.get_homecall(spot.de_call)[:6] + ':' if spot.de_call else '???:'!s:<7}" + frequency = f"{(spot.freq / 1000.0):10.1f}" dx_call = f"{spot.dx_call!s:<12}" - comment = f"{spot.comment[:29]:<30}" + comment = f"{spot.comment.encode('ascii', errors='ignore').decode()[:29]:<30}" if spot.time: timestamp = datetime.fromtimestamp(spot.time, tz=pytz.utc).strftime("%H%M") + "Z" else: diff --git a/templates/add_spot.html b/templates/add_spot.html index 583505b..087702c 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 7a18ae8..760b795 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -83,7 +83,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index 7737dc8..8b77f3a 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,8 +76,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index da7a6e6..7cd3d3e 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 %}