mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-02 16:09:24 +01:00
Add supybot.plugins.Weather.convert, which determines weather or not whether
will convert temperature to the configured unit.
This commit is contained in:
parent
5d8f0156fb
commit
403a561671
@ -226,9 +226,13 @@ class Weather(callbacks.Privmsg):
|
|||||||
city = city.strip()
|
city = city.strip()
|
||||||
state = state.strip()
|
state = state.strip()
|
||||||
temp = self._tempregex.search(html)
|
temp = self._tempregex.search(html)
|
||||||
|
convert = self.registryValue('convert', msg.args[0])
|
||||||
if temp is not None:
|
if temp is not None:
|
||||||
(temp, deg, unit) = temp.groups()
|
(temp, deg, unit) = temp.groups()
|
||||||
|
if convert:
|
||||||
temp = self._getTemp(int(temp), deg, unit, msg.args[0])
|
temp = self._getTemp(int(temp), deg, unit, msg.args[0])
|
||||||
|
else:
|
||||||
|
temp = deg.join((temp, unit))
|
||||||
conds = self._condregex.search(html)
|
conds = self._condregex.search(html)
|
||||||
if conds is not None:
|
if conds is not None:
|
||||||
conds = conds.group(1)
|
conds = conds.group(1)
|
||||||
@ -237,6 +241,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
if chill is not None:
|
if chill is not None:
|
||||||
chill = chill.group(1)
|
chill = chill.group(1)
|
||||||
chill = utils.htmlToText(chill)
|
chill = utils.htmlToText(chill)
|
||||||
|
if convert:
|
||||||
tempsplit = self._temp.search(chill)
|
tempsplit = self._temp.search(chill)
|
||||||
if tempsplit:
|
if tempsplit:
|
||||||
(chill, deg, unit) = tempsplit.groups()
|
(chill, deg, unit) = tempsplit.groups()
|
||||||
@ -247,9 +252,11 @@ class Weather(callbacks.Privmsg):
|
|||||||
if heat is not None:
|
if heat is not None:
|
||||||
heat = heat.group(1)
|
heat = heat.group(1)
|
||||||
heat = utils.htmlToText(heat)
|
heat = utils.htmlToText(heat)
|
||||||
|
if convert:
|
||||||
tempsplit = self._temp.search(heat)
|
tempsplit = self._temp.search(heat)
|
||||||
if tempsplit:
|
if tempsplit:
|
||||||
(heat, deg, unit) = tempsplit.groups()
|
(heat, deg, unit) = tempsplit.groups()
|
||||||
|
if convert:
|
||||||
heat = self._getTemp(int(heat), deg, unit,msg.args[0])
|
heat = self._getTemp(int(heat), deg, unit,msg.args[0])
|
||||||
if float(heat[:-2]) > float(temp[:-2]):
|
if float(heat[:-2]) > float(temp[:-2]):
|
||||||
index = ' (Heat Index: %s)' % heat
|
index = ' (Heat Index: %s)' % heat
|
||||||
@ -304,11 +311,15 @@ class Weather(callbacks.Privmsg):
|
|||||||
conds = self._conds.search(text)
|
conds = self._conds.search(text)
|
||||||
humidity = self._humidity.search(text)
|
humidity = self._humidity.search(text)
|
||||||
wind = self._wind.search(text)
|
wind = self._wind.search(text)
|
||||||
|
convert = self.registryValue('convert', msg.args[0])
|
||||||
if location and temp:
|
if location and temp:
|
||||||
location = location.group(1)
|
location = location.group(1)
|
||||||
location = location.split('-')[-1].strip()
|
location = location.split('-')[-1].strip()
|
||||||
(temp, deg, unit) = temp.groups()
|
(temp, deg, unit) = temp.groups()
|
||||||
|
if convert:
|
||||||
temp = self._getTemp(int(temp), deg, unit, msg.args[0])
|
temp = self._getTemp(int(temp), deg, unit, msg.args[0])
|
||||||
|
else:
|
||||||
|
temp = deg.join((temp, unit))
|
||||||
resp = 'The current temperature in %s is %s.' % (location, temp)
|
resp = 'The current temperature in %s is %s.' % (location, temp)
|
||||||
resp = [resp]
|
resp = [resp]
|
||||||
if conds is not None:
|
if conds is not None:
|
||||||
@ -330,6 +341,10 @@ 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',
|
||||||
|
registry.Boolean(True, """Determines whether the weather commands will
|
||||||
|
automatically convert weather units to the unit specified in
|
||||||
|
supybot.plugins.Weather.temperatureUnit."""))
|
||||||
|
|
||||||
Class = Weather
|
Class = Weather
|
||||||
|
|
||||||
|
@ -73,5 +73,27 @@ if network:
|
|||||||
def testNoEscapingWebError(self):
|
def testNoEscapingWebError(self):
|
||||||
self.assertNotRegexp('ham "buenos aires"', 'WebError')
|
self.assertNotRegexp('ham "buenos aires"', 'WebError')
|
||||||
|
|
||||||
|
def testConvertConfig(self):
|
||||||
|
try:
|
||||||
|
convert = conf.supybot.plugins.Weather.convert()
|
||||||
|
unit = conf.supybot.plugins.Weather.temperatureUnit()
|
||||||
|
conf.supybot.plugins.Weather.convert.setValue(False)
|
||||||
|
conf.supybot.plugins.Weather.temperatureUnit.setValue('C')
|
||||||
|
self.assertRegexp('ham london, gb', r'-?\d+.C')
|
||||||
|
self.assertRegexp('ham 02115', r'-?\d+.F')
|
||||||
|
conf.supybot.plugins.Weather.temperatureUnit.setValue('F')
|
||||||
|
self.assertRegexp('ham london, gb', r'-?\d+.C')
|
||||||
|
self.assertRegexp('ham 02115', r'-?\d+.F')
|
||||||
|
conf.supybot.plugins.Weather.convert.setValue(True)
|
||||||
|
conf.supybot.plugins.Weather.temperatureUnit.setValue('C')
|
||||||
|
self.assertRegexp('ham london, gb', r'-?\d+.C')
|
||||||
|
self.assertRegexp('ham 02115', r'-?\d+.C')
|
||||||
|
conf.supybot.plugins.Weather.temperatureUnit.setValue('F')
|
||||||
|
self.assertRegexp('ham london, gb', r'-?\d+.F')
|
||||||
|
self.assertRegexp('ham 02115', r'-?\d+.F')
|
||||||
|
finally:
|
||||||
|
conf.supybot.plugins.Weather.convert.setValue(convert)
|
||||||
|
conf.supybot.plugins.Weather.temperatureUnit.setValue(unit)
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user