mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-02 16:31:11 -05:00
Weather: reintroduce disableColoredTemp option
This commit is contained in:
parent
1f12245f05
commit
3a81f9b70c
@ -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:
|
||||||
|
67
plugin.py
67
plugin.py
@ -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,27 +204,30 @@ 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 f < 10.0:
|
if not self.registryValue('disableColoredTemp', channel):
|
||||||
color = 'light blue'
|
if f < 10.0:
|
||||||
elif 10.0 <= f <= 32.0:
|
color = 'light blue'
|
||||||
color = 'teal'
|
elif 10.0 <= f <= 32.0:
|
||||||
elif 32.1 <= f <= 50.0:
|
color = 'teal'
|
||||||
color = 'blue'
|
elif 32.1 <= f <= 50.0:
|
||||||
elif 50.1 <= f <= 60.0:
|
color = 'blue'
|
||||||
color = 'light green'
|
elif 50.1 <= f <= 60.0:
|
||||||
elif 60.1 <= f <= 70.0:
|
color = 'light green'
|
||||||
color = 'green'
|
elif 60.1 <= f <= 70.0:
|
||||||
elif 70.1 <= f <= 80.0:
|
color = 'green'
|
||||||
color = 'yellow'
|
elif 70.1 <= f <= 80.0:
|
||||||
elif 80.1 <= f <= 90.0:
|
color = 'yellow'
|
||||||
color = 'orange'
|
elif 80.1 <= f <= 90.0:
|
||||||
elif f > 90.0:
|
color = 'orange'
|
||||||
color = 'red'
|
elif f > 90.0:
|
||||||
else:
|
color = 'red'
|
||||||
color = 'light grey'
|
else:
|
||||||
|
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'],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user