Weather: reintroduce disableColoredTemp option

This commit is contained in:
James Lu 2015-07-09 22:47:04 -07:00
parent 1f12245f05
commit 3a81f9b70c
2 changed files with 37 additions and 33 deletions

View File

@ -38,6 +38,7 @@ conf.registerGlobalValue(Weather, 'showUpdated',
registry.Boolean(False, ("""Determines whether the bot will show the data's "last updated" time by default."""))) registry.Boolean(False, ("""Determines whether the bot will show the data's "last updated" time by default.""")))
conf.registerGlobalValue(Weather, 'lang', conf.registerGlobalValue(Weather, 'lang',
registry.String('EN', ("""Determines the language used by the plugin."""))) registry.String('EN', ("""Determines the language used by the plugin.""")))
conf.registerChannelValue(Weather, 'disableColoredTemp',
registry.Boolean(False, """If True, this will disable coloring temperatures based on values."""))
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=250: # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=250:

View File

@ -194,7 +194,7 @@ class Weather(callbacks.Plugin):
except KeyError: except KeyError:
return "unknown" return "unknown"
def _temp(self, f, c=None): def _temp(self, channel, f, c=None):
"""Returns a colored string based on the temperature.""" """Returns a colored string based on the temperature."""
# lets be safe and wrap in a try/except because we can't always trust data purity. # lets be safe and wrap in a try/except because we can't always trust data purity.
@ -204,7 +204,9 @@ class Weather(callbacks.Plugin):
f = int(f) f = int(f)
if not c: if not c:
c = int((f - 32) * 5/9) c = int((f - 32) * 5/9)
s = "{0}F/{1}C".format(f, c)
# determine color. # determine color.
if not self.registryValue('disableColoredTemp', channel):
if f < 10.0: if f < 10.0:
color = 'light blue' color = 'light blue'
elif 10.0 <= f <= 32.0: elif 10.0 <= f <= 32.0:
@ -223,8 +225,9 @@ class Weather(callbacks.Plugin):
color = 'red' color = 'red'
else: else:
color = 'light grey' color = 'light grey'
s = ircutils.mircColor(s, color)
# return. # return.
return ircutils.mircColor(("{0}F/{1}C".format(f, c)), color) return s
except ValueError as e: except ValueError as e:
self.log.info("Weather: ValueError trying to convert temp: {0} message: {1}".format(f, e)) self.log.info("Weather: ValueError trying to convert temp: {0} message: {1}".format(f, e))
return f return f
@ -345,11 +348,11 @@ class Weather(callbacks.Plugin):
Location must be one of: US state/city (CA/San_Francisco), zip code, country/city (Australia/Sydney), or an airport code (KJFK). Location must be one of: US state/city (CA/San_Francisco), zip code, country/city (Australia/Sydney), or an airport code (KJFK).
Ex: 10021 or Sydney, Australia or KJFK Ex: 10021 or Sydney, Australia or KJFK
""" """
apikey = self.registryValue('apiKey') apikey = self.registryValue('apiKey')
if not apikey: if not apikey:
irc.error("No Wunderground API key was defined. Set 'config plugins.Weather.apiKey' and reload the plugin.", irc.error("No Wunderground API key was defined. Set 'config plugins.Weather.apiKey' and reload the plugin.",
Raise=True) Raise=True)
channel = msg.args[0]
# urlargs will be used to build the url to query the API. # urlargs will be used to build the url to query the API.
# besides lang, these are unmutable values that should not be changed. # besides lang, these are unmutable values that should not be changed.
@ -437,19 +440,19 @@ class Weather(callbacks.Plugin):
outdata['observation'] = '1hr ago' outdata['observation'] = '1hr ago'
else: else:
outdata['observation'] = '{0}hrs ago'.format(s/3600) outdata['observation'] = '{0}hrs ago'.format(s/3600)
outdata['temp'] = self._temp(data['current_observation']['temp_f']) outdata['temp'] = self._temp(channel, data['current_observation']['temp_f'])
# pressure. # pressure.
pin = str(data['current_observation']['pressure_in']) + 'in' pin = str(data['current_observation']['pressure_in']) + 'in'
pmb = str(data['current_observation']['pressure_mb']) + 'mb' pmb = str(data['current_observation']['pressure_mb']) + 'mb'
outdata['pressure'] = "{0}/{1}".format(pin, pmb) outdata['pressure'] = "{0}/{1}".format(pin, pmb)
# dewpoint. # dewpoint.
outdata['dewpoint'] = self._temp(data['current_observation']['dewpoint_f']) outdata['dewpoint'] = self._temp(channel, data['current_observation']['dewpoint_f'])
# heatindex. # heatindex.
outdata['heatindex'] = self._temp(data['current_observation']['heat_index_f']) outdata['heatindex'] = self._temp(channel, data['current_observation']['heat_index_f'])
# windchill. # windchill.
outdata['windchill'] = self._temp(data['current_observation']['windchill_f']) outdata['windchill'] = self._temp(channel, data['current_observation']['windchill_f'])
# feels like # feels like
outdata['feelslike'] = self._temp(data['current_observation']['feelslike_f']) outdata['feelslike'] = self._temp(channel, data['current_observation']['feelslike_f'])
# visibility. # visibility.
vmi = str(data['current_observation']['visibility_mi']) + 'mi' vmi = str(data['current_observation']['visibility_mi']) + 'mi'
vkm = str(data['current_observation']['visibility_km']) + 'km' vkm = str(data['current_observation']['visibility_km']) + 'km'
@ -502,11 +505,11 @@ class Weather(callbacks.Plugin):
try: try:
outdata['highyear'] = data['almanac']['temp_high'].get('recordyear') outdata['highyear'] = data['almanac']['temp_high'].get('recordyear')
outdata['lowyear'] = data['almanac']['temp_low'].get('recordyear') outdata['lowyear'] = data['almanac']['temp_low'].get('recordyear')
outdata['highaverage'] = self._temp(data['almanac']['temp_high']['average']['F']) outdata['highaverage'] = self._temp(channel, data['almanac']['temp_high']['average']['F'])
outdata['lowaverage'] = self._temp(data['almanac']['temp_low']['average']['F']) outdata['lowaverage'] = self._temp(channel, data['almanac']['temp_low']['average']['F'])
if outdata['highyear'] != "NA" and outdata['lowyear'] != "NA": if outdata['highyear'] != "NA" and outdata['lowyear'] != "NA":
outdata['highrecord'] = self._temp(data['almanac']['temp_high']['record']['F']) outdata['highrecord'] = self._temp(channel, data['almanac']['temp_high']['record']['F'])
outdata['lowrecord'] = self._temp(data['almanac']['temp_low']['record']['F']) outdata['lowrecord'] = self._temp(channel, data['almanac']['temp_low']['record']['F'])
else: else:
outdata['highrecord'] = outdata['lowrecord'] = "NA" outdata['highrecord'] = outdata['lowrecord'] = "NA"
except KeyError: except KeyError:
@ -538,8 +541,8 @@ class Weather(callbacks.Plugin):
if args['forecast']: if args['forecast']:
fullforecastdata = {} # key = day (int), value = dict of forecast data. fullforecastdata = {} # key = day (int), value = dict of forecast data.
for forecastday in data['forecast']['simpleforecast']['forecastday']: for forecastday in data['forecast']['simpleforecast']['forecastday']:
high = self._temp(forecastday['high']['fahrenheit']) high = self._temp(channel, forecastday['high']['fahrenheit'])
low = self._temp(forecastday['low']['fahrenheit']) low = self._temp(channel, forecastday['low']['fahrenheit'])
tmpdict = {'day': forecastday['date']['weekday_short'], tmpdict = {'day': forecastday['date']['weekday_short'],
'symbol': self._weatherSymbol(forecastday['icon']), 'symbol': self._weatherSymbol(forecastday['icon']),
'text': forecastday['conditions'], 'text': forecastday['conditions'],