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:
|
else:
|
||||||
try:
|
try:
|
||||||
location = current['display_location']['full']
|
location = current['display_location']['full']
|
||||||
reply = "Conditions for {0:s}: ".format(location)
|
reply = "Conditions for {0:s}: ".format(location)
|
||||||
|
|
||||||
weather_str = current['weather']
|
weather_str = current['weather']
|
||||||
if weather_str != '':
|
if weather_str != '':
|
||||||
|
@ -158,41 +158,41 @@ class Weather(Module):
|
||||||
|
|
||||||
humidity_str = current['relative_humidity']
|
humidity_str = current['relative_humidity']
|
||||||
if humidity_str != '':
|
if humidity_str != '':
|
||||||
reply += "Humidity: {0:s}. ".format(humidity_str)
|
reply += "Humidity: {0:s}. ".format(humidity_str)
|
||||||
|
|
||||||
wind_str = current['wind_string']
|
wind_str = current['wind_string']
|
||||||
if wind_str != '':
|
if wind_str != '':
|
||||||
reply += "Wind: {0:s}. ".format(wind_str)
|
reply += "Wind: {0:s}. ".format(wind_str)
|
||||||
|
|
||||||
pressure_in = current['pressure_in']
|
pressure_in = current['pressure_in']
|
||||||
pressure_trend = current['pressure_trend']
|
pressure_trend = current['pressure_trend']
|
||||||
if pressure_in != '':
|
if pressure_in != '':
|
||||||
reply += "Pressure: {0:s}\"".format(pressure_in)
|
reply += "Pressure: {0:s}\"".format(pressure_in)
|
||||||
if pressure_trend != '':
|
if pressure_trend != '':
|
||||||
reply += " and {0:s}".format("dropping" if pressure_trend == '-' else "rising")
|
reply += " and {0:s}".format("dropping" if pressure_trend == '-' else "rising")
|
||||||
reply += ". "
|
reply += ". "
|
||||||
|
|
||||||
heat_index_str = current['heat_index_string']
|
heat_index_str = current['heat_index_string']
|
||||||
if heat_index_str != '' and heat_index_str != 'NA':
|
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']
|
windchill_str = current['windchill_string']
|
||||||
if windchill_str != '' and windchill_str != 'NA':
|
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']
|
visibility_mi = current['visibility_mi']
|
||||||
if 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']
|
precip_in = current['precip_today_in']
|
||||||
if precip_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']
|
observation_time = current['observation_time']
|
||||||
if observation_time != '':
|
if observation_time != '':
|
||||||
reply += "{0:s}. ".format(observation_time)
|
reply += "{0:s}. ".format(observation_time)
|
||||||
|
|
||||||
return reply.rstrip()
|
return self._prettify_weather_strings(reply.rstrip())
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
self.log.error("error or unexpected results in conditions reply")
|
self.log.error("error or unexpected results in conditions reply")
|
||||||
self.log.exception(e)
|
self.log.exception(e)
|
||||||
|
@ -217,5 +217,18 @@ class Weather(Module):
|
||||||
|
|
||||||
return api_key
|
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
|
# vi:tabstop=4:expandtab:autoindent
|
||||||
# kate: indent-mode python;indent-width 4;replace-tabs on;
|
# kate: indent-mode python;indent-width 4;replace-tabs on;
|
||||||
|
|
Loading…
Reference in New Issue