Updates addressing PR comments
Added location_info() to util/location API to return a dict of all location information. Updated modules/contrib/publicip to use that API. Changed modules/contrib/publicip refresh period back to 60 minutes. Changed /util/location API from 'country_name' back to 'name'
This commit is contained in:
parent
6f137c4927
commit
a97a7fe507
2 changed files with 31 additions and 11 deletions
|
@ -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: <ip> (<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"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue