mirror of
https://github.com/vincentbernat/i3wm-configuration.git
synced 2025-07-03 06:44:21 +02:00
polybar-weather: switch to MaxMind for location
In the future, I can get a key from here: https://support.maxmind.com/getting-started-with-geolite2/. The issue with ip-api.com is that the city is often wrong.
This commit is contained in:
parent
7f04bb6cf0
commit
6be90d5830
1 changed files with 12 additions and 4 deletions
|
@ -16,13 +16,21 @@ logger = logging.getLogger("polybar-weather")
|
||||||
|
|
||||||
def get_location():
|
def get_location():
|
||||||
"""Return current location as latitude/longitude tuple."""
|
"""Return current location as latitude/longitude tuple."""
|
||||||
logger.debug("query ip-api.com for location")
|
logger.debug("query MaxMind for location")
|
||||||
r = requests.get("http://ip-api.com/json")
|
r = requests.get(
|
||||||
|
"https://www.maxmind.com/geoip/v2.1/city/me",
|
||||||
|
headers={"referer": "https://www.maxmind.com/en/locate-my-ip-address"},
|
||||||
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
data = r.json()
|
data = r.json()
|
||||||
logger.debug("current location data: %s", data)
|
logger.debug("current location data: %s", data)
|
||||||
logger.info(f'current location: {data["city"]}, {data["country"]}')
|
logger.info(
|
||||||
return ((data["lat"], data["lon"]), data["city"])
|
f'current location: {data["city"]["names"]["en"]}, {data["country"]["names"]["en"]}'
|
||||||
|
)
|
||||||
|
return (
|
||||||
|
(data["location"]["latitude"], data["location"]["longitude"]),
|
||||||
|
data["city"]["names"]["en"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_weather(apikey, latitude, longitude):
|
def get_weather(apikey, latitude, longitude):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue