From 29f3e7b5158bdaaf67438053871b71d8ef417907 Mon Sep 17 00:00:00 2001 From: Justin Wheeler Date: Mon, 12 Jun 2017 22:26:33 -0400 Subject: [PATCH] Add weather icons. Add icons to the weather output to show condition to go with current temperature. --- bumblebee/modules/weather.py | 22 ++++++++++++++++++++++ themes/icons/awesome-fonts.json | 7 +++++++ 2 files changed, 29 insertions(+) diff --git a/bumblebee/modules/weather.py b/bumblebee/modules/weather.py index 01420e3..92a2745 100644 --- a/bumblebee/modules/weather.py +++ b/bumblebee/modules/weather.py @@ -51,6 +51,27 @@ class Module(bumblebee.engine.Module): return u"?" 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): timestamp = 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 = json.loads(requests.get(weather_url).text) self._temperature = int(weather['main']['temp']) + self._weather = weather['weather'][0]['main'].lower() self._valid = True except RequestException: self._valid = False diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index 5a602a6..bf95f55 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -108,5 +108,12 @@ }, "publicip": { "prefix": "  " + }, + "weather": { + "clouds": { "prefix": "" }, + "rain": { "prefix": "" }, + "snow": { "prefix": "" }, + "clear": { "prefix": "" }, + "thunder": { "prefix": "" } } }