mirror of
https://github.com/progval/Limnoria.git
synced 2025-04-27 13:31:08 -05:00
Improve Weather.wunder's UV report and add heat index reporting
This commit is contained in:
parent
bc1027d8cc
commit
0585ccb090
@ -85,7 +85,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
callbacks.Privmsg.callCommand(self, method, irc, msg, *L)
|
callbacks.Privmsg.callCommand(self, method, irc, msg, *L)
|
||||||
except webutils.WebError, e:
|
except webutils.WebError, e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
|
|
||||||
def weather(self, irc, msg, args):
|
def weather(self, irc, msg, args):
|
||||||
# This specifically does not have a docstring.
|
# This specifically does not have a docstring.
|
||||||
channel = None
|
channel = None
|
||||||
@ -102,7 +102,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
realCommandName = self.registryValue('command', channel)
|
realCommandName = self.registryValue('command', channel)
|
||||||
realCommand = getattr(self, realCommandName)
|
realCommand = getattr(self, realCommandName)
|
||||||
realCommand(irc, msg, args)
|
realCommand(irc, msg, args)
|
||||||
|
|
||||||
def _toCelsius(self, temp, unit):
|
def _toCelsius(self, temp, unit):
|
||||||
if unit == 'K':
|
if unit == 'K':
|
||||||
return temp - 273.15
|
return temp - 273.15
|
||||||
@ -111,6 +111,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
return temp
|
return temp
|
||||||
|
|
||||||
|
_temp = re.compile(r'(-?\d+)(.*?)(F|C)')
|
||||||
def _getTemp(self, temp, deg, unit, chan):
|
def _getTemp(self, temp, deg, unit, chan):
|
||||||
assert unit == unit.upper()
|
assert unit == unit.upper()
|
||||||
assert temp == int(temp)
|
assert temp == int(temp)
|
||||||
@ -141,7 +142,6 @@ class Weather(callbacks.Privmsg):
|
|||||||
_hamTemp = re.compile(
|
_hamTemp = re.compile(
|
||||||
r'<td valign="top" align="right"><strong><font face="arial">'
|
r'<td valign="top" align="right"><strong><font face="arial">'
|
||||||
r'(-?\d+)(.*?)(F|C)</font></strong></td>', re.I)
|
r'(-?\d+)(.*?)(F|C)</font></strong></td>', re.I)
|
||||||
_temp = re.compile(r'(-?\d+)(.*?)(F|C)')
|
|
||||||
_hamChill = re.compile(
|
_hamChill = re.compile(
|
||||||
r'Wind Chill</font></strong>:</small></td>\s+<td align="right">'
|
r'Wind Chill</font></strong>:</small></td>\s+<td align="right">'
|
||||||
r'<small><font face="arial">([^N][^<]+)</font></small></td>',
|
r'<small><font face="arial">([^N][^<]+)</font></small></td>',
|
||||||
@ -151,7 +151,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
r'<small><font face="arial">([^N][^<]+)</font></small></td>',
|
r'<small><font face="arial">([^N][^<]+)</font></small></td>',
|
||||||
re.I | re.S)
|
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',
|
||||||
'il', 'in', 'ks', 'ky', 'la', 'ma', 'md',
|
'il', 'in', 'ks', 'ky', 'la', 'ma', 'md',
|
||||||
'me', 'mi', 'mn', 'mo', 'ms', 'mt', 'nc',
|
'me', 'mi', 'mn', 'mo', 'ms', 'mt', 'nc',
|
||||||
@ -170,7 +170,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
|
|
||||||
Returns the approximate weather conditions for a given city.
|
Returns the approximate weather conditions for a given city.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
#If we received more than one argument, then we have received
|
#If we received more than one argument, then we have received
|
||||||
#a city and state argument that we need to process.
|
#a city and state argument that we need to process.
|
||||||
if len(args) > 1:
|
if len(args) > 1:
|
||||||
@ -185,7 +185,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
city = city.lower()
|
city = city.lower()
|
||||||
#We must break the States up into two sections. The US and
|
#We must break the States up into two sections. The US and
|
||||||
#Canada are the only countries that require a State argument.
|
#Canada are the only countries that require a State argument.
|
||||||
|
|
||||||
if state in self._realStates:
|
if state in self._realStates:
|
||||||
country = 'us'
|
country = 'us'
|
||||||
elif state in self._fakeStates:
|
elif state in self._fakeStates:
|
||||||
@ -211,7 +211,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
#We received a single argument. Zipcode or station id.
|
#We received a single argument. Zipcode or station id.
|
||||||
else:
|
else:
|
||||||
zip = privmsgs.getArgs(args)
|
zip = privmsgs.getArgs(args)
|
||||||
zip = zip.replace(',', '')
|
zip = zip.replace(',', '')
|
||||||
zip = zip.lower()
|
zip = zip.lower()
|
||||||
url = 'http://www.hamweather.net/cgi-bin/hw3/hw3.cgi?' \
|
url = 'http://www.hamweather.net/cgi-bin/hw3/hw3.cgi?' \
|
||||||
'config=&forecast=zandh&pands=%s&Submit=GO' % zip
|
'config=&forecast=zandh&pands=%s&Submit=GO' % zip
|
||||||
@ -219,7 +219,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
if 'was not found' in html:
|
if 'was not found' in html:
|
||||||
irc.error('No such location could be found.')
|
irc.error('No such location could be found.')
|
||||||
return
|
return
|
||||||
|
|
||||||
headData = self._hamLoc.search(html)
|
headData = self._hamLoc.search(html)
|
||||||
if headData is not None:
|
if headData is not None:
|
||||||
(city, state, country) = headData.groups()
|
(city, state, country) = headData.groups()
|
||||||
@ -355,6 +355,9 @@ class Weather(callbacks.Privmsg):
|
|||||||
_wunderDew = re.compile(r'Dew Point:</td><td[^>]+><b>\s+<nobr><b>'
|
_wunderDew = re.compile(r'Dew Point:</td><td[^>]+><b>\s+<nobr><b>'
|
||||||
r'(-?\d+)</b> (°)(F)</nobr>',
|
r'(-?\d+)</b> (°)(F)</nobr>',
|
||||||
re.I | re.S)
|
re.I | re.S)
|
||||||
|
_wunderHeat = re.compile(
|
||||||
|
r'HeatIndex:</td><td[^>]+><b>\s+<nobr><b>(\d+)</b> ([^F]+)(F)<',
|
||||||
|
re.I | re.S)
|
||||||
_wunderWind = re.compile(
|
_wunderWind = re.compile(
|
||||||
r'Wind:</td><td[^>]+>\s+<b>\s+<nobr><b>(\d+)</b> (mph)'
|
r'Wind:</td><td[^>]+>\s+<b>\s+<nobr><b>(\d+)</b> (mph)'
|
||||||
r'</nobr>\s+/\s+<nobr><b>(\d+)</b> (km/h)</nobr>\s+</b>'
|
r'</nobr>\s+/\s+<nobr><b>(\d+)</b> (km/h)</nobr>\s+</b>'
|
||||||
@ -363,10 +366,10 @@ class Weather(callbacks.Privmsg):
|
|||||||
r'Pressure:</td><td[^<]+><b>\s+<b>(\d+\.\d+)</b> (in)\s+/\s+'
|
r'Pressure:</td><td[^<]+><b>\s+<b>(\d+\.\d+)</b> (in)\s+/\s+'
|
||||||
r'<b>(\d+)</b> (hPa)', re.I | re.S)
|
r'<b>(\d+)</b> (hPa)', re.I | re.S)
|
||||||
_wunderVisible = re.compile(
|
_wunderVisible = re.compile(
|
||||||
r'Visibility:</td><td[^>]+><b>\s+<nobr><b>(\w+)</b> (miles)'
|
r'Visibility:</td><td[^>]+><b>\s+<nobr><b>([\w.]+)</b> (miles)'
|
||||||
r'</nobr>\s+/\s+<nobr><b>(\w+)</b> (kilometers)</nobr>',
|
r'</nobr>\s+/\s+<nobr><b>([\w.]+)</b> (kilometers)</nobr>',
|
||||||
re.I | re.S)
|
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)
|
_wunderTime = re.compile(r'Updated:\s+<b>([\w\s:,]+)</b>', re.I | re.S)
|
||||||
def wunder(self, irc, msg, args):
|
def wunder(self, irc, msg, args):
|
||||||
"""<US zip code | US/Canada city, state | Foreign city, country>
|
"""<US zip code | US/Canada city, state | Foreign city, country>
|
||||||
@ -404,6 +407,12 @@ class Weather(callbacks.Privmsg):
|
|||||||
time = ''
|
time = ''
|
||||||
resp = ['The current temperature at %s is %s%s.' %\
|
resp = ['The current temperature at %s is %s%s.' %\
|
||||||
(location, temp, time)]
|
(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)
|
conds = self._wunderCond.search(text)
|
||||||
if conds is not None:
|
if conds is not None:
|
||||||
resp.append('Conditions: %s.' % conds.group(1))
|
resp.append('Conditions: %s.' % conds.group(1))
|
||||||
@ -433,7 +442,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
resp.append('Visibility: %s %s (%s %s).' % vis.groups())
|
resp.append('Visibility: %s %s (%s %s).' % vis.groups())
|
||||||
uv = self._wunderUv.search(text)
|
uv = self._wunderUv.search(text)
|
||||||
if uv is not None:
|
if uv is not None:
|
||||||
resp.append('UV: %s' % uv.group(1))
|
resp.append('UV: %s%s' % uv.groups())
|
||||||
resp = map(utils.htmlToText, resp)
|
resp = map(utils.htmlToText, resp)
|
||||||
irc.reply(' '.join(resp))
|
irc.reply(' '.join(resp))
|
||||||
else:
|
else:
|
||||||
@ -444,7 +453,7 @@ conf.registerChannelValue(conf.supybot.plugins.Weather, 'temperatureUnit',
|
|||||||
WeatherUnit('Fahrenheit', """Sets the default temperature unit to use when
|
WeatherUnit('Fahrenheit', """Sets the default temperature unit to use when
|
||||||
reporting the weather."""))
|
reporting the weather."""))
|
||||||
conf.registerChannelValue(conf.supybot.plugins.Weather, 'command',
|
conf.registerChannelValue(conf.supybot.plugins.Weather, 'command',
|
||||||
WeatherCommand('cnn', """Sets the default command to use when retrieving
|
WeatherCommand('cnn', """Sets the default command to use when retrieving
|
||||||
the weather. Command must be one of %s.""" %
|
the weather. Command must be one of %s.""" %
|
||||||
utils.commaAndify(Weather.weatherCommands, And='or')))
|
utils.commaAndify(Weather.weatherCommands, And='or')))
|
||||||
conf.registerChannelValue(conf.supybot.plugins.Weather, 'convert',
|
conf.registerChannelValue(conf.supybot.plugins.Weather, 'convert',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user