Weather: weather conditions readability fixes
* bold (^B) city name, condition elements * replace 32F and 32 F with 32°F
This commit is contained in:
		
							parent
							
								
									6426df9ece
								
							
						
					
					
						commit
						425db7be81
					
				| @ -130,7 +130,7 @@ class Weather(Module): | ||||
|         else: | ||||
|             try: | ||||
|                 location = current['display_location']['full'] | ||||
|                 reply = "Conditions for {0:s}: ".format(location) | ||||
|                 reply = "Conditions for {0:s}: ".format(location) | ||||
| 
 | ||||
|                 weather_str = current['weather'] | ||||
|                 if weather_str != '': | ||||
| @ -158,41 +158,41 @@ class Weather(Module): | ||||
| 
 | ||||
|                 humidity_str = current['relative_humidity'] | ||||
|                 if humidity_str != '': | ||||
|                     reply += "Humidity: {0:s}. ".format(humidity_str) | ||||
|                     reply += "Humidity: {0:s}. ".format(humidity_str) | ||||
| 
 | ||||
|                 wind_str = current['wind_string'] | ||||
|                 if wind_str != '': | ||||
|                     reply += "Wind: {0:s}. ".format(wind_str) | ||||
|                     reply += "Wind: {0:s}. ".format(wind_str) | ||||
| 
 | ||||
|                 pressure_in = current['pressure_in'] | ||||
|                 pressure_trend = current['pressure_trend'] | ||||
|                 if pressure_in != '': | ||||
|                     reply += "Pressure: {0:s}\"".format(pressure_in) | ||||
|                     reply += "Pressure: {0:s}\"".format(pressure_in) | ||||
|                     if pressure_trend != '': | ||||
|                         reply += " and {0:s}".format("dropping" if pressure_trend == '-' else "rising") | ||||
|                     reply += ". " | ||||
| 
 | ||||
|                 heat_index_str = current['heat_index_string'] | ||||
|                 if heat_index_str != '' and heat_index_str != 'NA': | ||||
|                     reply += "Heat index: {0:s}. ".format(heat_index_str) | ||||
|                     reply += "Heat index: {0:s}. ".format(heat_index_str) | ||||
| 
 | ||||
|                 windchill_str = current['windchill_string'] | ||||
|                 if windchill_str != '' and windchill_str != 'NA': | ||||
|                     reply += "Wind chill: {0:s}. ".format(windchill_str) | ||||
|                     reply += "Wind chill: {0:s}. ".format(windchill_str) | ||||
| 
 | ||||
|                 visibility_mi = current['visibility_mi'] | ||||
|                 if visibility_mi != '': | ||||
|                     reply += "Visibility: {0:s} miles. ".format(visibility_mi) | ||||
|                     reply += "Visibility: {0:s} miles. ".format(visibility_mi) | ||||
| 
 | ||||
|                 precip_in = current['precip_today_in'] | ||||
|                 if precip_in != '': | ||||
|                     reply += "Precipitation today: {0:s}\". ".format(precip_in) | ||||
|                     reply += "Precipitation today: {0:s}\". ".format(precip_in) | ||||
| 
 | ||||
|                 observation_time = current['observation_time'] | ||||
|                 if observation_time != '': | ||||
|                     reply += "{0:s}. ".format(observation_time) | ||||
| 
 | ||||
|                 return reply.rstrip() | ||||
|                 return self._prettify_weather_strings(reply.rstrip()) | ||||
|             except KeyError as e: | ||||
|                 self.log.error("error or unexpected results in conditions reply") | ||||
|                 self.log.exception(e) | ||||
| @ -217,5 +217,18 @@ class Weather(Module): | ||||
| 
 | ||||
|         return api_key | ||||
| 
 | ||||
|     def _prettify_weather_strings(self, weather_str): | ||||
|         """ | ||||
|         Clean up output strings. | ||||
| 
 | ||||
|         For example, turn 32F into 32°F in input string. | ||||
| 
 | ||||
|         Input: | ||||
|             weather_str --- the string to clean up | ||||
| 
 | ||||
|         """ | ||||
| 
 | ||||
|         return re.sub(r'(\d+)\s*([FC])', r'\1°\2', weather_str) | ||||
| 
 | ||||
| # vi:tabstop=4:expandtab:autoindent | ||||
| # kate: indent-mode python;indent-width 4;replace-tabs on; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user