Improve Weather.wunder's UV report and add heat index reporting

This commit is contained in:
James Vega 2004-07-18 22:25:12 +00:00
parent bc1027d8cc
commit 0585ccb090

View File

@ -111,6 +111,7 @@ class Weather(callbacks.Privmsg):
else:
return temp
_temp = re.compile(r'(-?\d+)(.*?)(F|C)')
def _getTemp(self, temp, deg, unit, chan):
assert unit == unit.upper()
assert temp == int(temp)
@ -141,7 +142,6 @@ class Weather(callbacks.Privmsg):
_hamTemp = re.compile(
r'<td valign="top" align="right"><strong><font face="arial">'
r'(-?\d+)(.*?)(F|C)</font></strong></td>', re.I)
_temp = re.compile(r'(-?\d+)(.*?)(F|C)')
_hamChill = re.compile(
r'Wind Chill</font></strong>:</small></td>\s+<td align="right">'
r'<small><font face="arial">([^N][^<]+)</font></small></td>',
@ -355,6 +355,9 @@ class Weather(callbacks.Privmsg):
_wunderDew = re.compile(r'Dew Point:</td><td[^>]+><b>\s+<nobr><b>'
r'(-?\d+)</b>&nbsp;(&#176;)(F)</nobr>',
re.I | re.S)
_wunderHeat = re.compile(
r'HeatIndex:</td><td[^>]+><b>\s+<nobr><b>(\d+)</b>&nbsp;([^F]+)(F)<',
re.I | re.S)
_wunderWind = re.compile(
r'Wind:</td><td[^>]+>\s+<b>\s+<nobr><b>(\d+)</b>&nbsp;(mph)'
r'</nobr>\s+/\s+<nobr><b>(\d+)</b>&nbsp;(km/h)</nobr>\s+</b>'
@ -363,10 +366,10 @@ class Weather(callbacks.Privmsg):
r'Pressure:</td><td[^<]+><b>\s+<b>(\d+\.\d+)</b>&nbsp;(in)\s+/\s+'
r'<b>(\d+)</b>&nbsp;(hPa)', re.I | re.S)
_wunderVisible = re.compile(
r'Visibility:</td><td[^>]+><b>\s+<nobr><b>(\w+)</b>&nbsp;(miles)'
r'</nobr>\s+/\s+<nobr><b>(\w+)</b>&nbsp;(kilometers)</nobr>',
r'Visibility:</td><td[^>]+><b>\s+<nobr><b>([\w.]+)</b>&nbsp;(miles)'
r'</nobr>\s+/\s+<nobr><b>([\w.]+)</b>&nbsp;(kilometers)</nobr>',
re.I | re.S)
_wunderUv = re.compile(r'UV:</td><td[^>]+><b>(\d\d?)</b>', re.I | re.S)
_wunderUv = re.compile(r'UV:</td><td[^>]+><b>(\d\d?)</b>( out of \d\d?)', re.I | re.S)
_wunderTime = re.compile(r'Updated:\s+<b>([\w\s:,]+)</b>', re.I | re.S)
def wunder(self, irc, msg, args):
"""<US zip code | US/Canada city, state | Foreign city, country>
@ -404,6 +407,12 @@ class Weather(callbacks.Privmsg):
time = ''
resp = ['The current temperature at %s is %s%s.' %\
(location, temp, time)]
heat = self._wunderHeat.search(text)
if heat is not None:
(heat, deg, unit) = map(str.strip, heat.groups())
if convert:
heat = self._getTemp(int(heat), deg, unit, msg.args[0])
resp.append('Heat Index: %s.' % heat)
conds = self._wunderCond.search(text)
if conds is not None:
resp.append('Conditions: %s.' % conds.group(1))
@ -433,7 +442,7 @@ class Weather(callbacks.Privmsg):
resp.append('Visibility: %s %s (%s %s).' % vis.groups())
uv = self._wunderUv.search(text)
if uv is not None:
resp.append('UV: %s' % uv.group(1))
resp.append('UV: %s%s' % uv.groups())
resp = map(utils.htmlToText, resp)
irc.reply(' '.join(resp))
else: