mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-23 10:34:19 +01:00
If wunderground finds multiple locations, let's return the results for the
first location they list. Also, default Weather.weather to Weather.wunder
This commit is contained in:
parent
2e8bd9a012
commit
bb36f4877f
@ -368,6 +368,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
_wunderUv = re.compile(r'UV:</td><td[^>]+><b>(\d\d?)</b>( out of \d\d?)',
|
_wunderUv = re.compile(r'UV:</td><td[^>]+><b>(\d\d?)</b>( out of \d\d?)',
|
||||||
re.I | re.S)
|
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)
|
||||||
|
_wunderMultiLoc = re.compile(r'<a href="([^"]+)', 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>
|
||||||
|
|
||||||
@ -379,8 +380,16 @@ class Weather(callbacks.Privmsg):
|
|||||||
if 'Search not found' in text:
|
if 'Search not found' in text:
|
||||||
irc.error(noLocationError, Raise=True)
|
irc.error(noLocationError, Raise=True)
|
||||||
if 'Search results for' in text:
|
if 'Search results for' in text:
|
||||||
irc.error('Multiple locations found. Please be more specific.',
|
text = text[text.index('Search results for'):]
|
||||||
Raise=True)
|
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)
|
location = self._wunderLoc.search(text)
|
||||||
temp = self._wunderFTemp.search(text)
|
temp = self._wunderFTemp.search(text)
|
||||||
convert = self.registryValue('convert', msg.args[0])
|
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
|
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('wunder', """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…
Reference in New Issue
Block a user