From beec864ac8a790edeb8df2df68442d0aafdcc77b Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Mon, 28 Sep 2020 19:24:47 +0300 Subject: Implement normalize_lat_lng() --- iss/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'iss/utils.py') diff --git a/iss/utils.py b/iss/utils.py index 326d835..656d4e3 100644 --- a/iss/utils.py +++ b/iss/utils.py @@ -7,6 +7,14 @@ def seconds_to_minutes(secs): return f"{secs // 60}:{secs % 60:02}" +def normalize_lat_lng(lat, lng): + if lat[0] not in "NS" or lng[0] not in "EW": + raise Exception("Lat/lng must be formatted as N12.345 and E67.890") + nlat = float(lat[1:]) * (-1 if lat[0] == "S" else 1) + nlng = float(lng[1:]) * (-1 if lng[0] == "W" else 1) + return nlat, nlng + + def deg_to_cardinal(deg): cardinals = [ "N", -- cgit v1.3.1