diff options
| author | Yuval Adam <_@yuv.al> | 2020-10-21 17:16:27 +0300 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2020-10-21 17:16:27 +0300 |
| commit | 743de3a39e9490d42f45fafa8f20c5d4b092637b (patch) | |
| tree | da6ab7d48f822efb41d45edfdaebdc7304ccc0bc /iss/utils.py | |
| parent | fc09f4b8d9824234da44ef565ffb932f35f05095 (diff) | |
Location class WIPlocation-class
Diffstat (limited to 'iss/utils.py')
| -rw-r--r-- | iss/utils.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/iss/utils.py b/iss/utils.py index 23667cc..a075463 100644 --- a/iss/utils.py +++ b/iss/utils.py @@ -40,4 +40,20 @@ def deg_to_cardinal(deg): "NW", "NNW", ] - return cardinals[round((deg % 360) / 22.5) % 16] + n = len(cardinals) + degs = 360 / n + return cardinals[round((deg % 360) / degs) % n] + + +class Location(object): + def __init__(self, lat, lng): + self.lat = lat + self.lng = lng + + @classmethod + def from_labelled(cls, 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 cls(nlat, nlng) |
