Skip to content

Commit

Permalink
Add parse_udc to ham_utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mbridak committed Aug 24, 2024
1 parent 42a8c2d commit f121e1f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions not1mm/lib/ham_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,29 @@ def distance_with_latlon(grid1: str, lat2: float, lon2: float) -> float:
logger.debug("lat1:%d lon1:%d lat2:%d lon2:%d", lat1, lon1, lat2, lon2)
# lat2, lon2 = gridtolatlon(grid2)
return round(haversine(lon1, lat1, lon2, lat2))


def parse_udc(filename: str) -> dict:
"""
simply parses a n1mm style udc file and returns a dict with key value pairs.
"""

udc_contest = {}
the_good_stuff = False

try:
with open(filename, "r", encoding="utf-8") as file_descriptor:
for line in file_descriptor:
if "[CONTEST]" in line.upper():
the_good_stuff = True
continue
if "=" in line and the_good_stuff is True:
try:
key, value = line.split("=")
udc_contest[key.strip()] = value.strip()
except ValueError:
...
except FileNotFoundError:
logger.debug("UDC file not found.")
return {}
return udc_contest

0 comments on commit f121e1f

Please sign in to comment.