From 2ed1cf2e4a4aa5fceb9806b3374d404b3ca0c2f5 Mon Sep 17 00:00:00 2001 From: jesopo Date: Tue, 18 Jun 2019 16:34:51 +0100 Subject: [PATCH] Only try to show !w country when it is available. closes #72 --- modules/weather.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/weather.py b/modules/weather.py index be3bb316..202eb0fb 100644 --- a/modules/weather.py +++ b/modules/weather.py @@ -49,8 +49,11 @@ class Module(ModuleManager.BaseModule): page = utils.http.request(URL_WEATHER, get_params=args, json=True) if page: if "weather" in page.data: - location = "%s, %s" % (page.data["name"], page.data["sys"][ - "country"]) + location_parts = [page.data["name"]] + if "country" in page.data["sys"]: + location_parts.append(page.data["sys"]["country"]) + location_str = ", ".join(location_parts) + celsius = "%dC" % page.data["main"]["temp"] fahrenheit = "%dF" % ((page.data["main"]["temp"]*(9/5))+32) description = page.data["weather"][0]["description"].title() @@ -59,7 +62,7 @@ class Module(ModuleManager.BaseModule): event["stdout"].write( "(%s) %s/%s | %s | Humidity: %s | Wind: %s" % ( - location, celsius, fahrenheit, description, humidity, + location_str, celsius, fahrenheit, description, humidity, wind_speed)) else: event["stderr"].write("No weather information for this location")