From bb36f4877f9cea03ef8781fb230538e8455adc26 Mon Sep 17 00:00:00 2001 From: James Vega Date: Wed, 18 Aug 2004 19:32:15 +0000 Subject: [PATCH] If wunderground finds multiple locations, let's return the results for the first location they list. Also, default Weather.weather to Weather.wunder --- plugins/Weather.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/Weather.py b/plugins/Weather.py index ee96554d6..7c78dd482 100644 --- a/plugins/Weather.py +++ b/plugins/Weather.py @@ -368,6 +368,7 @@ class Weather(callbacks.Privmsg): _wunderUv = re.compile(r'UV:]+>(\d\d?)( out of \d\d?)', re.I | re.S) _wunderTime = re.compile(r'Updated:\s+([\w\s:,]+)', re.I | re.S) + _wunderMultiLoc = re.compile(r' @@ -379,8 +380,16 @@ class Weather(callbacks.Privmsg): if 'Search not found' in text: irc.error(noLocationError, Raise=True) if 'Search results for' in text: - irc.error('Multiple locations found. Please be more specific.', - Raise=True) + text = text[text.index('Search results for'):] + newloc = self._wunderMultiLoc.search(text) + if newloc is None: + irc.error('Multiple locations found. ' + 'Please be more specific.', Raise=True) + url = 'http://www.wunderground.com%s' % newloc.group(1) + try: + text = webutils.getUrl(url) + except webutils.WebError, e: + irc.error(str(e), Raise=True) location = self._wunderLoc.search(text) temp = self._wunderFTemp.search(text) convert = self.registryValue('convert', msg.args[0]) @@ -445,7 +454,7 @@ conf.registerChannelValue(conf.supybot.plugins.Weather, 'temperatureUnit', WeatherUnit('Fahrenheit', """Sets the default temperature unit to use when reporting the weather.""")) conf.registerChannelValue(conf.supybot.plugins.Weather, 'command', - WeatherCommand('cnn', """Sets the default command to use when retrieving + WeatherCommand('wunder', """Sets the default command to use when retrieving the weather. Command must be one of %s.""" % utils.commaAndify(Weather.weatherCommands, And='or'))) conf.registerChannelValue(conf.supybot.plugins.Weather, 'convert',