From cb73cc3b73f89ee944271a31e4b7ed0fa96e1ed2 Mon Sep 17 00:00:00 2001 From: James Vega Date: Fri, 9 Jan 2004 02:50:23 +0000 Subject: [PATCH] Add some logic to the wind chill/heat index regexes so that they don't grab N/A and clean up the construction of the index string. --- plugins/Weather.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/Weather.py b/plugins/Weather.py index cb0a0e6c4..69fce5db2 100644 --- a/plugins/Weather.py +++ b/plugins/Weather.py @@ -75,10 +75,12 @@ class Weather(callbacks.Privmsg): r'([^<]+)', re.I) _chillregex = re.compile( r'Wind Chill:\s+' - r'([^<]+)', re.I | re.S) + r'([^N][^<]+)', + re.I | re.S) _heatregex = re.compile( r'Heat Index:\s+' - r'([^<]+)', re.I | re.S) + r'([^N][^<]+)', + re.I | re.S) # States _realStates = sets.Set(['ak', 'al', 'ar', 'az', 'ca', 'co', 'ct', 'dc', 'de', 'fl', 'ga', 'hi', 'ia', 'id', @@ -168,21 +170,18 @@ class Weather(callbacks.Privmsg): conds = self._condregex.search(html) if conds: conds = conds.group(1) + index = '' chill = self._chillregex.search(html) if chill: #self.log.warning(chill.groups()) chill = chill.group(1) + if int(chill[:-2]) < int(temp[:-2]): + index = ' (Wind Chill: %s)' % chill heat = self._heatregex.search(html) if heat: heat = heat.group(1) - - if int(heat[:-2]) > int(temp[:-2]): - index = ' (Heat Index: %s)' % heat - elif int(chill[:-2]) < int(temp[:-2]): - index = ' (Wind Chill: %s)' % chill - else: - index = '' - + if int(heat[:-2]) > int(temp[:-2]): + index = ' (Heat Index: %s)' % heat if temp and conds and city and state: conds = conds.replace('Tsra', 'Thunder Storms') s = 'The current temperature in %s, %s is %s%s. Conditions: %s' % \