mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 15:44:06 +01:00
Fixed some things with WeatherUnit and temperature parsing in Weather.cnn
This commit is contained in:
parent
d3b8c25255
commit
6f24ebecce
@ -51,14 +51,13 @@ unitAbbrevs['c'] = 'celsius'
|
|||||||
unitAbbrevs['ce'] = 'celsius'
|
unitAbbrevs['ce'] = 'celsius'
|
||||||
|
|
||||||
class WeatherUnit(registry.String):
|
class WeatherUnit(registry.String):
|
||||||
def set(self, s):
|
def setValue(self, s):
|
||||||
original = getattr(self, 'value', self.default)
|
s = s.lower()
|
||||||
registry.String.set(self, s)
|
|
||||||
s = self.value.lower()
|
|
||||||
if s not in unitAbbrevs:
|
if s not in unitAbbrevs:
|
||||||
setattr(self, 'value', original)
|
|
||||||
raise registry.InvalidRegistryValue,\
|
raise registry.InvalidRegistryValue,\
|
||||||
'Unit must be one of fahrenheit, celsius, or kelvin.'
|
'Unit must be one of fahrenheit, celsius, or kelvin.'
|
||||||
|
s = unitAbbrevs[s].capitalize()
|
||||||
|
registry.String.setValue(self, s)
|
||||||
|
|
||||||
class WeatherCommand(registry.String):
|
class WeatherCommand(registry.String):
|
||||||
def set(self, s):
|
def set(self, s):
|
||||||
@ -72,7 +71,7 @@ class WeatherCommand(registry.String):
|
|||||||
|
|
||||||
conf.registerPlugin('Weather')
|
conf.registerPlugin('Weather')
|
||||||
conf.registerChannelValue(conf.supybot.plugins.Weather, 'preferredUnit',
|
conf.registerChannelValue(conf.supybot.plugins.Weather, 'preferredUnit',
|
||||||
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, 'weatherCommand',
|
conf.registerChannelValue(conf.supybot.plugins.Weather, 'weatherCommand',
|
||||||
WeatherCommand('cnn', """Sets the default command to use when retrieving
|
WeatherCommand('cnn', """Sets the default command to use when retrieving
|
||||||
@ -92,11 +91,11 @@ class Weather(callbacks.Privmsg):
|
|||||||
default = unitAbbrevs[default]
|
default = unitAbbrevs[default]
|
||||||
unit = unit.lower()
|
unit = unit.lower()
|
||||||
if unitAbbrevs[unit] == default:
|
if unitAbbrevs[unit] == default:
|
||||||
return deg.join([str(temp), unit.upper()])
|
return deg.join([temp, unit.upper()])
|
||||||
try:
|
try:
|
||||||
temp = int(temp)
|
temp = int(temp)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return deg.join([temp, unit])
|
return deg.join([temp, unit.upper()])
|
||||||
if unit == 'f':
|
if unit == 'f':
|
||||||
temp = (temp - 32) * 5 / 9
|
temp = (temp - 32) * 5 / 9
|
||||||
if default == 'kelvin':
|
if default == 'kelvin':
|
||||||
@ -113,7 +112,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
elif default == 'fahrenheit':
|
elif default == 'fahrenheit':
|
||||||
temp = temp * 9 / 5 + 32
|
temp = temp * 9 / 5 + 32
|
||||||
unit = 'F'
|
unit = 'F'
|
||||||
return deg.join([str(temp), unit])
|
return deg.join([str(temp), unit.upper()])
|
||||||
|
|
||||||
_cityregex = re.compile(
|
_cityregex = re.compile(
|
||||||
r'<td><font size="4" face="arial"><b>'
|
r'<td><font size="4" face="arial"><b>'
|
||||||
@ -247,7 +246,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
irc.error('The format of the page was odd.')
|
irc.error('The format of the page was odd.')
|
||||||
|
|
||||||
_cnnUrl = 'http://weather.cnn.com/weather/search?wsearch='
|
_cnnUrl = 'http://weather.cnn.com/weather/search?wsearch='
|
||||||
_fTemp = re.compile(r'(-?\d+°F)</span>', re.I | re.S)
|
_fTemp = re.compile(r'(-?\d+)(°)(F)</span>', re.I | re.S)
|
||||||
_conds = re.compile(r'align="center"><b>([^<]+)</b></div></td>', re.I|re.S)
|
_conds = re.compile(r'align="center"><b>([^<]+)</b></div></td>', re.I|re.S)
|
||||||
_humidity = re.compile(r'Rel. Humidity: <b>(\d+%)</b>', re.I | re.S)
|
_humidity = re.compile(r'Rel. Humidity: <b>(\d+%)</b>', re.I | re.S)
|
||||||
_wind = re.compile(r'Wind: <b>([^<]+)</b>', re.I | re.S)
|
_wind = re.compile(r'Wind: <b>([^<]+)</b>', re.I | re.S)
|
||||||
@ -292,8 +291,7 @@ class Weather(callbacks.Privmsg):
|
|||||||
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 = temp.group(1)
|
(temp, deg, unit) = temp.groups()
|
||||||
(temp, deg, unit) = (temp[:-2], temp[-2], temp[-1])
|
|
||||||
temp = self._getTemp(temp, deg, unit, msg.args[0])
|
temp = self._getTemp(temp, deg, unit, msg.args[0])
|
||||||
resp = 'The current temperature in %s is %s.' % (location, temp)
|
resp = 'The current temperature in %s is %s.' % (location, temp)
|
||||||
resp = [resp]
|
resp = [resp]
|
||||||
|
Loading…
Reference in New Issue
Block a user