Only try to show !w country when it is available. closes #72

This commit is contained in:
jesopo 2019-06-18 16:34:51 +01:00
parent 3c51348fec
commit 2ed1cf2e4a

View file

@ -49,8 +49,11 @@ class Module(ModuleManager.BaseModule):
page = utils.http.request(URL_WEATHER, get_params=args, json=True) page = utils.http.request(URL_WEATHER, get_params=args, json=True)
if page: if page:
if "weather" in page.data: if "weather" in page.data:
location = "%s, %s" % (page.data["name"], page.data["sys"][ location_parts = [page.data["name"]]
"country"]) if "country" in page.data["sys"]:
location_parts.append(page.data["sys"]["country"])
location_str = ", ".join(location_parts)
celsius = "%dC" % page.data["main"]["temp"] celsius = "%dC" % page.data["main"]["temp"]
fahrenheit = "%dF" % ((page.data["main"]["temp"]*(9/5))+32) fahrenheit = "%dF" % ((page.data["main"]["temp"]*(9/5))+32)
description = page.data["weather"][0]["description"].title() description = page.data["weather"][0]["description"].title()
@ -59,7 +62,7 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write( event["stdout"].write(
"(%s) %s/%s | %s | Humidity: %s | Wind: %s" % ( "(%s) %s/%s | %s | Humidity: %s | Wind: %s" % (
location, celsius, fahrenheit, description, humidity, location_str, celsius, fahrenheit, description, humidity,
wind_speed)) wind_speed))
else: else:
event["stderr"].write("No weather information for this location") event["stderr"].write("No weather information for this location")