Add weather icons.

Add icons to the weather output to show condition to go with current
temperature.
This commit is contained in:
Justin Wheeler 2017-06-12 22:26:33 -04:00
parent 5d89c3dfc1
commit 29f3e7b515
2 changed files with 29 additions and 0 deletions

View file

@ -51,6 +51,27 @@ class Module(bumblebee.engine.Module):
return u"?" return u"?"
return u"{}°{}".format(self._temperature, self._unit_suffix()) return u"{}°{}".format(self._temperature, self._unit_suffix())
def state( self, widget ):
if self._valid:
if "thunderstorm" in self._weather:
return [ 'thunder' ]
elif "drizzle" in self._weather:
return [ 'rain' ]
elif "rain" in self._weather:
return [ 'rain' ]
elif "snow" in self._weather:
return [ 'snow' ]
elif "sleet" in self._weather:
return [ 'sleet' ]
elif "clear" in self._weather:
return [ 'clear' ]
elif "cloud" in self._weather:
return [ 'clouds' ]
else:
return []
return []
def update(self, widgets): def update(self, widgets):
timestamp = int(time.time()) timestamp = int(time.time())
if self._nextcheck < int(time.time()): if self._nextcheck < int(time.time()):
@ -67,6 +88,7 @@ class Module(bumblebee.engine.Module):
weather_url = "{url}&q={city}".format(url=weather_url, city=self._location) weather_url = "{url}&q={city}".format(url=weather_url, city=self._location)
weather = json.loads(requests.get(weather_url).text) weather = json.loads(requests.get(weather_url).text)
self._temperature = int(weather['main']['temp']) self._temperature = int(weather['main']['temp'])
self._weather = weather['weather'][0]['main'].lower()
self._valid = True self._valid = True
except RequestException: except RequestException:
self._valid = False self._valid = False

View file

@ -108,5 +108,12 @@
}, },
"publicip": { "publicip": {
"prefix": "  " "prefix": "  "
},
"weather": {
"clouds": { "prefix": "" },
"rain": { "prefix": "" },
"snow": { "prefix": "" },
"clear": { "prefix": "" },
"thunder": { "prefix": "" }
} }
} }