Skip to content

Instantly share code, notes, and snippets.

@beaugunderson
Created June 20, 2023 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beaugunderson/120155e842618634be15255f95305241 to your computer and use it in GitHub Desktop.
Save beaugunderson/120155e842618634be15255f95305241 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import re
import sys
from telnetlib import Telnet
from env_tools import apply_env
apply_env()
HAMALERT_LOGIN = os.getenv("HAMALERT_LOGIN")
HAMALERT_PASSWORD = os.getenv("HAMALERT_PASSWORD")
if not HAMALERT_LOGIN or not HAMALERT_PASSWORD:
print("HAMALERT_LOGIN and HAMALERT_PASSWORD are required")
sys.exit(1)
RE_OPTIONS = (
# DX de K9LC: 14074.0 VC9FEMBOY -11dB 0302Z
re.compile(
rb"DX de (?P<reporter>\w+):\s+(?P<frequency>[0-9.]+)\s+(?P<call>[A-Z0-9]+)\s+(?P<signal>[-+0-9]+dB)\s+(?P<time>\d+Z)"
),
)
with Telnet("hamalert.org", 7300) as hamalert:
hamalert.read_until(b"login: ")
hamalert.write(HAMALERT_LOGIN.encode("ascii") + b"\n")
hamalert.read_until(b"password: ")
hamalert.write(HAMALERT_PASSWORD.encode("ascii") + b"\n")
while True:
index, match, data = hamalert.expect(RE_OPTIONS)
if index == 0 and match:
print(
"\t".join(
(
match.group("call").decode("ascii"),
match.group("frequency").decode("ascii"),
match.group("time").decode("ascii"),
match.group("signal").decode("ascii"),
match.group("reporter").decode("ascii"),
)
)
)
else:
print(index, match, data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment