mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Fix bug #1032402, and convert to use commands.wrap.
This commit is contained in:
parent
ed61675016
commit
89f6d285b0
@ -51,10 +51,11 @@ import BeautifulSoup
|
|||||||
|
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.utils as utils
|
import supybot.utils as utils
|
||||||
import supybot.webutils as webutils
|
import supybot.commands as commands
|
||||||
import supybot.ircutils as ircutils
|
import supybot.ircutils as ircutils
|
||||||
import supybot.privmsgs as privmsgs
|
import supybot.privmsgs as privmsgs
|
||||||
import supybot.registry as registry
|
import supybot.registry as registry
|
||||||
|
import supybot.webutils as webutils
|
||||||
import supybot.callbacks as callbacks
|
import supybot.callbacks as callbacks
|
||||||
|
|
||||||
unitAbbrevs = utils.abbrev(['Fahrenheit', 'Celsius', 'Centigrade', 'Kelvin'])
|
unitAbbrevs = utils.abbrev(['Fahrenheit', 'Celsius', 'Centigrade', 'Kelvin'])
|
||||||
@ -116,7 +117,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
location, ignoreNoUser=True)
|
location, ignoreNoUser=True)
|
||||||
realCommandName = self.registryValue('command', channel)
|
realCommandName = self.registryValue('command', channel)
|
||||||
realCommand = getattr(self, realCommandName)
|
realCommand = getattr(self, realCommandName)
|
||||||
ret = realCommand(irc, msg, args)
|
ret = realCommand(irc, msg, args, location)
|
||||||
|
|
||||||
def _toCelsius(self, temp, unit):
|
def _toCelsius(self, temp, unit):
|
||||||
if unit == 'K':
|
if unit == 'K':
|
||||||
@ -180,7 +181,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
# Certain countries are expected to use a standard abbreviation
|
# Certain countries are expected to use a standard abbreviation
|
||||||
# The weather we pull uses weird codes. Map obvious ones here.
|
# The weather we pull uses weird codes. Map obvious ones here.
|
||||||
_hamCountryMap = {'uk': 'gb'}
|
_hamCountryMap = {'uk': 'gb'}
|
||||||
def ham(self, irc, msg, args):
|
def ham(self, irc, msg, args, loc):
|
||||||
"""<US zip code | US/Canada city, state | Foreign city, country>
|
"""<US zip code | US/Canada city, state | Foreign city, country>
|
||||||
|
|
||||||
Returns the approximate weather conditions for a given city.
|
Returns the approximate weather conditions for a given city.
|
||||||
@ -188,16 +189,15 @@ class Weather(callbacks.Privmsg):
|
|||||||
|
|
||||||
#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 ' ' in loc:
|
||||||
#If we received more than 1 argument, then we got a city with a
|
#If we received more than 1 argument, then we got a city with a
|
||||||
#multi-word name. ie ['Garden', 'City', 'KS'] instead of
|
#multi-word name. ie ['Garden', 'City', 'KS'] instead of
|
||||||
#['Liberal', 'KS']. We join it together with a + to pass
|
#['Liberal', 'KS']. We join it together with a + to pass
|
||||||
#to our query
|
#to our query
|
||||||
state = args.pop()
|
loc = rsplit(loc, None, 1)
|
||||||
state = state.lower()
|
state = loc.pop().lower()
|
||||||
city = '+'.join(args)
|
city = '+'.join(loc)
|
||||||
city = city.rstrip(',')
|
city = city.rstrip(',').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.
|
||||||
|
|
||||||
@ -224,8 +224,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 = loc.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
|
||||||
@ -288,6 +287,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
else:
|
else:
|
||||||
irc.error('The format of the page was odd.')
|
irc.error('The format of the page was odd.')
|
||||||
|
ham=commands.wrap(ham, ['something'])
|
||||||
|
|
||||||
_cnnUrl = 'http://weather.cnn.com/weather/search?wsearch='
|
_cnnUrl = 'http://weather.cnn.com/weather/search?wsearch='
|
||||||
_cnnFTemp = re.compile(r'(-?\d+)(°)(F)</span>', re.I | re.S)
|
_cnnFTemp = re.compile(r'(-?\d+)(°)(F)</span>', re.I | re.S)
|
||||||
@ -299,26 +299,25 @@ class Weather(callbacks.Privmsg):
|
|||||||
# Certain countries are expected to use a standard abbreviation
|
# Certain countries are expected to use a standard abbreviation
|
||||||
# The weather we pull uses weird codes. Map obvious ones here.
|
# The weather we pull uses weird codes. Map obvious ones here.
|
||||||
_cnnCountryMap = {'uk': 'en', 'de': 'ge'}
|
_cnnCountryMap = {'uk': 'en', 'de': 'ge'}
|
||||||
def cnn(self, irc, msg, args):
|
def cnn(self, irc, msg, args, loc):
|
||||||
"""<US zip code | US/Canada city, state | Foreign city, country>
|
"""<US zip code | US/Canada city, state | Foreign city, country>
|
||||||
|
|
||||||
Returns the approximate weather conditions for a given city.
|
Returns the approximate weather conditions for a given city.
|
||||||
"""
|
"""
|
||||||
if len(args) > 1:
|
if ' ' in loc:
|
||||||
#If we received more than 1 argument, then we got a city with a
|
#If we received more than 1 argument, then we got a city with a
|
||||||
#multi-word name. ie ['Garden', 'City', 'KS'] instead of
|
#multi-word name. ie ['Garden', 'City', 'KS'] instead of
|
||||||
#['Liberal', 'KS']. We join it together with a + to pass
|
#['Liberal', 'KS'].
|
||||||
#to our query
|
loc = rsplit(loc, None, 1)
|
||||||
state = args.pop().lower()
|
state = loc.pop().lower()
|
||||||
city = ' '.join(args)
|
city = ' '.join(loc)
|
||||||
city = city.rstrip(',').lower()
|
city = city.rstrip(',').lower()
|
||||||
if state in self._cnnCountryMap:
|
if state in self._cnnCountryMap:
|
||||||
state = self._cnnCountryMap[state]
|
state = self._cnnCountryMap[state]
|
||||||
loc = ' '.join([city, state])
|
loc = ' '.join([city, state])
|
||||||
else:
|
else:
|
||||||
#We received a single argument. Zipcode or station id.
|
#We received a single argument. Zipcode or station id.
|
||||||
zip = privmsgs.getArgs(args)
|
loc = loc.replace(',', '')
|
||||||
loc = zip.replace(',', '').lower()
|
|
||||||
url = '%s%s' % (self._cnnUrl, urllib.quote(loc))
|
url = '%s%s' % (self._cnnUrl, urllib.quote(loc))
|
||||||
text = webutils.getUrl(url) # Errors caught in callCommand.
|
text = webutils.getUrl(url) # Errors caught in callCommand.
|
||||||
if "No search results" in text or "does not match a zip code" in text:
|
if "No search results" in text or "does not match a zip code" in text:
|
||||||
@ -348,17 +347,17 @@ class Weather(callbacks.Privmsg):
|
|||||||
irc.reply(' '.join(resp))
|
irc.reply(' '.join(resp))
|
||||||
else:
|
else:
|
||||||
irc.error('Could not find weather information.')
|
irc.error('Could not find weather information.')
|
||||||
|
cnn=commands.wrap(cnn, ['something'])
|
||||||
|
|
||||||
_wunderUrl = 'http://mobile.wunderground.com/cgi-bin/' \
|
_wunderUrl = 'http://mobile.wunderground.com/cgi-bin/' \
|
||||||
'findweather/getForecast?query='
|
'findweather/getForecast?query='
|
||||||
_wunderLoc = re.compile(r'Page (.+?) Forecast</title>', re.I | re.S)
|
_wunderLoc = re.compile(r'Page (.+?) Forecast</title>', re.I | re.S)
|
||||||
_wunderMultiLoc = re.compile(r'<a href="([^"]+)', 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, loc):
|
||||||
"""<US zip code | US/Canada city, state | Foreign city, country>
|
"""<US zip code | US/Canada city, state | Foreign city, country>
|
||||||
|
|
||||||
Returns the approximate weather conditions for a given city.
|
Returns the approximate weather conditions for a given city.
|
||||||
"""
|
"""
|
||||||
loc = ' '.join(args)
|
|
||||||
url = '%s%s' % (self._wunderUrl, urllib.quote(loc))
|
url = '%s%s' % (self._wunderUrl, urllib.quote(loc))
|
||||||
text = webutils.getUrl(url)
|
text = webutils.getUrl(url)
|
||||||
if 'Search not found' in text:
|
if 'Search not found' in text:
|
||||||
@ -433,6 +432,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
irc.reply(' '.join(resp))
|
irc.reply(' '.join(resp))
|
||||||
else:
|
else:
|
||||||
irc.error('Could not find weather information.')
|
irc.error('Could not find weather information.')
|
||||||
|
wunder=commands.wrap(wunder, ['something'])
|
||||||
|
|
||||||
conf.registerPlugin('Weather')
|
conf.registerPlugin('Weather')
|
||||||
conf.registerChannelValue(conf.supybot.plugins.Weather, 'temperatureUnit',
|
conf.registerChannelValue(conf.supybot.plugins.Weather, 'temperatureUnit',
|
||||||
|
Loading…
Reference in New Issue
Block a user