mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-27 12:44:19 +01:00
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.
This commit is contained in:
parent
69aaea218f
commit
cb73cc3b73
@ -75,10 +75,12 @@ class Weather(callbacks.Privmsg):
|
|||||||
r'([^<]+)</font></strong></td>', re.I)
|
r'([^<]+)</font></strong></td>', re.I)
|
||||||
_chillregex = re.compile(
|
_chillregex = re.compile(
|
||||||
r'Wind Chill</font></strong>:</small></a></td>\s+<td align="right">'
|
r'Wind Chill</font></strong>:</small></a></td>\s+<td align="right">'
|
||||||
r'<small><font face="arial">([^<]+)</font></small></td>', re.I | re.S)
|
r'<small><font face="arial">([^N][^<]+)</font></small></td>',
|
||||||
|
re.I | re.S)
|
||||||
_heatregex = re.compile(
|
_heatregex = re.compile(
|
||||||
r'Heat Index</font></strong>:</small></a></td>\s+<td align="right">'
|
r'Heat Index</font></strong>:</small></a></td>\s+<td align="right">'
|
||||||
r'<small><font face="arial">([^<]+)</font></small></td>', re.I | re.S)
|
r'<small><font face="arial">([^N][^<]+)</font></small></td>',
|
||||||
|
re.I | re.S)
|
||||||
# States
|
# States
|
||||||
_realStates = sets.Set(['ak', 'al', 'ar', 'az', 'ca', 'co', 'ct',
|
_realStates = sets.Set(['ak', 'al', 'ar', 'az', 'ca', 'co', 'ct',
|
||||||
'dc', 'de', 'fl', 'ga', 'hi', 'ia', 'id',
|
'dc', 'de', 'fl', 'ga', 'hi', 'ia', 'id',
|
||||||
@ -168,21 +170,18 @@ class Weather(callbacks.Privmsg):
|
|||||||
conds = self._condregex.search(html)
|
conds = self._condregex.search(html)
|
||||||
if conds:
|
if conds:
|
||||||
conds = conds.group(1)
|
conds = conds.group(1)
|
||||||
|
index = ''
|
||||||
chill = self._chillregex.search(html)
|
chill = self._chillregex.search(html)
|
||||||
if chill:
|
if chill:
|
||||||
#self.log.warning(chill.groups())
|
#self.log.warning(chill.groups())
|
||||||
chill = chill.group(1)
|
chill = chill.group(1)
|
||||||
|
if int(chill[:-2]) < int(temp[:-2]):
|
||||||
|
index = ' (Wind Chill: %s)' % chill
|
||||||
heat = self._heatregex.search(html)
|
heat = self._heatregex.search(html)
|
||||||
if heat:
|
if heat:
|
||||||
heat = heat.group(1)
|
heat = heat.group(1)
|
||||||
|
if int(heat[:-2]) > int(temp[:-2]):
|
||||||
if int(heat[:-2]) > int(temp[:-2]):
|
index = ' (Heat Index: %s)' % heat
|
||||||
index = ' (Heat Index: %s)' % heat
|
|
||||||
elif int(chill[:-2]) < int(temp[:-2]):
|
|
||||||
index = ' (Wind Chill: %s)' % chill
|
|
||||||
else:
|
|
||||||
index = ''
|
|
||||||
|
|
||||||
if temp and conds and city and state:
|
if temp and conds and city and state:
|
||||||
conds = conds.replace('Tsra', 'Thunder Storms')
|
conds = conds.replace('Tsra', 'Thunder Storms')
|
||||||
s = 'The current temperature in %s, %s is %s%s. Conditions: %s' % \
|
s = 'The current temperature in %s, %s is %s%s. Conditions: %s' % \
|
||||||
|
Loading…
Reference in New Issue
Block a user