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:
Tom Watson 2022-07-06 19:37:29 +07:00
parent 6f137c4927
commit a97a7fe507
2 changed files with 31 additions and 11 deletions

View file

@ -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