From 2a47e84cc2414fc00b7092b7dcd5dfb85a2b55d5 Mon Sep 17 00:00:00 2001 From: dubwoc Date: Sat, 3 May 2014 12:01:15 -0400 Subject: [PATCH] Introduce a colorize option for the weather status plugin. Add an option to change the color and add an icon in the display based on the text returned from weather.com. For example, if the waether is considered "Sunny" by weather.com the weather text will be set to a golden yellow and a little snow will be added to the display. --- i3pystatus/weather.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/i3pystatus/weather.py b/i3pystatus/weather.py index 1f44b40..62e4759 100644 --- a/i3pystatus/weather.py +++ b/i3pystatus/weather.py @@ -19,6 +19,7 @@ class Weather(IntervalModule): settings = ( "location_code", + ("colorize", "Enable color with temperature and UTF-8 icons."), ("units", "Celsius (metric) or Fahrenheit (imperial)"), "format", ) @@ -26,6 +27,14 @@ class Weather(IntervalModule): units = "metric" format = "{current_temp}" + colorize = None + color_icons = {'Fair': (u'\u2600', '#FFCC00'), + 'Cloudy': (u'\u2601', '#F8F8FF'), + 'Rainy': (u'\u2614', '#CBD2C0'), + 'Sunny': (u'\u263C', '#FFFF00'), + 'Snow': (u'\u2603', '#FFFFFF'), + 'default': ('', None), + } @require(internet) def run(self): @@ -34,7 +43,18 @@ class Weather(IntervalModule): temperature = conditions['temperature'] humidity = conditions['humidity'] units = result['units'] - current_temp = '{t}°{d}'.format(t=temperature, d=units['temperature']) + color = None + current_temp = '{t}°{d} '.format(t=temperature, d=units['temperature']) + + if self.colorize: + icon, color = self.color_icons.get(conditions['text'], + self.color_icons['default']) + current_temp = '{t}°{d} {i}'.format(t=temperature, + d=units['temperature'], + i=icon) + color = color + self.output = { - "full_text": self.format.format(current_temp=current_temp, humidity=humidity) + "full_text": self.format.format(current_temp=current_temp, humidity=humidity), + "color": color }