diff --git a/bumblebee_status/modules/contrib/publicip.py b/bumblebee_status/modules/contrib/publicip.py index f65e3b7..d043fce 100644 --- a/bumblebee_status/modules/contrib/publicip.py +++ b/bumblebee_status/modules/contrib/publicip.py @@ -37,7 +37,7 @@ import util.location class Module(core.module.Module): - @core.decorators.every(minutes=5) + @core.decorators.every(minutes=60) def __init__(self, config, theme): super().__init__(config, theme, core.widget.Widget(self.public_ip)) @@ -48,7 +48,7 @@ class Module(core.module.Module): self.__country_name = "" # Country name associated with public IP address self.__country_code = "" # Country code associated with public IP address self.__city_name = "" # City name associated with public IP address - self.__coordinates = "" # Coordinated assoicated with public IP address + self.__coordinates = "" # Coordinates assoicated with public IP address # By default show: (<2 letter country code>) self._format = self.parameter("format", "{ip} ({country_code})") @@ -70,11 +70,13 @@ class Module(core.module.Module): def update(self): try: - self.__ip = util.location.public_ip() - self.__country_name = util.location.country_name() - self.__country_code = util.location.country_code() - self.__city_name = util.location.city_name() - __lat, __lon = util.location.coordinates() + __info = util.location.location_info() + self.__ip = __info["public_ip"] + self.__country_name = __info["country"] + self.__country_code = __info["country_code"] + self.__city_name = __info["city_name"] + __lat = __info["latitude"] + __lon = __info["longitude"] __lat = "{:.2f}".format(__lat) __lon = "{:.2f}".format(__lon) __output = __lat + "°N" + "," + " " + __lon + "°E" diff --git a/bumblebee_status/util/location.py b/bumblebee_status/util/location.py index 840baa0..1974773 100644 --- a/bumblebee_status/util/location.py +++ b/bumblebee_status/util/location.py @@ -50,7 +50,7 @@ __sources = [ "city": "city_name", "query": "public_ip", }, - } + }, ] @@ -87,8 +87,7 @@ def __get(name): def reset(): - """Resets the location library, ensuring that a new query will be started - """ + """Resets the location library, ensuring that a new query will be started""" global __next __next = 0 @@ -102,7 +101,7 @@ def coordinates(): return __get("latitude"), __get("longitude") -def country_name(): +def country(): """Returns the current country name :return: country name @@ -110,6 +109,7 @@ def country_name(): """ return __get("country_name") + def country_code(): """Returns the current country code @@ -118,6 +118,7 @@ def country_code(): """ return __get("country_code") + def city_name(): """Returns the current city name @@ -126,6 +127,7 @@ def city_name(): """ return __get("city_name") + def public_ip(): """Returns the current public IP @@ -135,4 +137,20 @@ def public_ip(): return __get("public_ip") +def location_info(): + """Returns the current location information + + :return: public IP, country name, country code, city name & coordinates + :rtype: dictionary + """ + return { + "public_ip": __get("public_ip"), + "country": __get("country_name"), + "country_code": __get("country_code"), + "city_name": __get("city_name"), + "latitude": __get("latitude"), + "longitude": __get("longitude"), + } + + # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4