From 911ba9c0ffd146e3df6573385de07a4495e50e1b Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 26 Dec 2021 18:36:59 +0100 Subject: [PATCH] weather: don't crash when no city --- bin/weather | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bin/weather b/bin/weather index 02b803f..a347341 100755 --- a/bin/weather +++ b/bin/weather @@ -25,13 +25,9 @@ def get_location(): r.raise_for_status() data = r.json() logger.debug("current location data: %s", data) - logger.info( - f'current location: {data["city"]["names"]["en"]}, {data["country"]["names"]["en"]}' - ) - return ( - (data["location"]["latitude"], data["location"]["longitude"]), - (data.get("city") or data["country"])["names"]["en"], - ) + location = (data.get("city") or data["country"])["names"]["en"] + logger.info(f"current location: {location}") + return ((data["location"]["latitude"], data["location"]["longitude"]), location) def get_weather(apikey, latitude, longitude):