From 01395c6b39b2b8152e31d5c3f4f41313f1b881d9 Mon Sep 17 00:00:00 2001 From: Erik Johnson Date: Thu, 7 Apr 2016 16:18:39 -0500 Subject: [PATCH] Catch "Showers" as "Rainy" weather condition (#356) * Catch "Showers" as "Rainy" weather condition Weather.com has a "Showers in the Vicinity" weather condition that I just happened to see this morning. This commit assigns this condition as "Rainy" so it is properly colorized. * Make "Clear / Windy" map to "Fair" weather condition Another odd weather condition from the weather.com API * Reverse icons for Fair and Sunny "Sunny" should have a filled-in sun icon as it implies a brighter weather condition than "Fair" does. * Properly detect "Sunny / Windy" as "Sunny" weather condition Also, do not check for similarly-named conditions if an exact match is found. * Properly detect "Fair / Windy" as "Fair" --- i3pystatus/weather/__init__.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/i3pystatus/weather/__init__.py b/i3pystatus/weather/__init__.py index 45ffe4e..7f1dd2e 100644 --- a/i3pystatus/weather/__init__.py +++ b/i3pystatus/weather/__init__.py @@ -84,12 +84,12 @@ class Weather(IntervalModule): colorize = False color_icons = { - 'Fair': (u'\u2600', '#ffcc00'), + 'Fair': (u'\u263c', '#ffcc00'), 'Cloudy': (u'\u2601', '#f8f8ff'), 'Partly Cloudy': (u'\u2601', '#f8f8ff'), # \u26c5 is not in many fonts 'Rainy': (u'\u26c8', '#cbd2c0'), 'Thunderstorm': (u'\u03de', '#cbd2c0'), - 'Sunny': (u'\u263c', '#ffff00'), + 'Sunny': (u'\u2600', '#ffff00'), 'Snow': (u'\u2603', '#ffffff'), 'default': ('', None), } @@ -113,17 +113,24 @@ class Weather(IntervalModule): Disambiguate similarly-named weather conditions, and return the icon and color that match. ''' - condition_lc = condition.lower() - if condition_lc == 'clear': - condition = 'Fair' - if 'cloudy' in condition_lc: - condition = 'Cloudy' - elif 'rain' in condition_lc: - condition = 'Rainy' - elif 'thunder' in condition_lc: - condition = 'Thunderstorm' - elif 'snow' in condition_lc: - condition = 'Snow' + if condition not in self.color_icons: + # Check for similarly-named conditions if no exact match found + condition_lc = condition.lower() + if 'cloudy' in condition_lc: + if 'partly' in condition_lc: + condition = 'Partly Cloudy' + else: + condition = 'Cloudy' + elif 'thunder' in condition_lc: + condition = 'Thunderstorm' + elif 'snow' in condition_lc: + condition = 'Snow' + elif 'rain' in condition_lc or 'showers' in condition_lc: + condition = 'Rainy' + elif 'sunny' in condition_lc: + condition = 'Sunny' + elif 'clear' in condition_lc or 'fair' in condition_lc: + condition = 'Fair' return self.color_icons['default'] \ if condition not in self.color_icons \