From 61fe7f6d3e2f9df32f4a58c46b23cb626689f9a8 Mon Sep 17 00:00:00 2001 From: tfwiii Date: Thu, 6 Oct 2022 13:49:37 +0700 Subject: [PATCH] Handled fail where core.location does not provide values for latitude and longitude. Added handling for coordinates N, S, E, W. --- bumblebee_status/modules/contrib/publicip.py | 25 ++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/bumblebee_status/modules/contrib/publicip.py b/bumblebee_status/modules/contrib/publicip.py index d79c2a1..ca0cd31 100644 --- a/bumblebee_status/modules/contrib/publicip.py +++ b/bumblebee_status/modules/contrib/publicip.py @@ -116,6 +116,8 @@ class Module(core.module.Module): def update(self): widget = self.widget() + __lat = None + __lon = None try: util.location.reset() @@ -123,10 +125,23 @@ class Module(core.module.Module): # Fetch fresh location information __info = util.location.location_info() - # Contstruct coordinates string - __lat = "{:.2f}".format(__info["latitude"]) - __lon = "{:.2f}".format(__info["longitude"]) - __coords = __lat + "°N" + "," + " " + __lon + "°E" + # Contstruct coordinates string if util.location has provided required info + if __lat and __lon: + __lat = "{:.2f}".format(__info["latitude"]) + __lon = "{:.2f}".format(__info["longitude"]) + if __lat < 0: + __coords = __lat + "°S" + else: + __coords = __lat + "°N" + __coords += "," + if __lon < 0: + __coords += __lon + "°W" + else: + __coords += __lon + "°E" + else: + __lat = "Unknown" + __lon = "Unknown" + __coords = "Unknown" # Set widget values widget.set("public_ip", __info["public_ip"]) @@ -139,6 +154,8 @@ class Module(core.module.Module): core.event.trigger("update", [widget.module.id], redraw_only=True) except Exception as ex: widget.set("public_ip", None) + print("OH NOES!") + print(__info) logging.error(str(ex)) def state(self, widget):