More progress..

This commit is contained in:
spline 2013-01-01 06:25:36 -05:00
parent 3fb47e4d12
commit 55ec489f73
2 changed files with 32 additions and 33 deletions

View File

@ -24,12 +24,12 @@ Weather = conf.registerPlugin('Weather')
conf.registerGlobalValue(Weather,'apiKey', registry.String('', ("""Your wunderground.com API key."""), private=True)) conf.registerGlobalValue(Weather,'apiKey', registry.String('', ("""Your wunderground.com API key."""), private=True))
conf.registerChannelValue(Weather,'useImperial', registry.Boolean(True, ("""Use imperial units? Defaults to yes."""))) conf.registerChannelValue(Weather,'useImperial', registry.Boolean(True, ("""Use imperial units? Defaults to yes.""")))
conf.registerChannelValue(Weather,'disableANSI', registry.Boolean(False, """Do not display any ANSI (color/bold) for channel.""")) conf.registerChannelValue(Weather,'disableANSI', registry.Boolean(False, """Do not display any ANSI (color/bold) for channel."""))
conf.registerChannelValue(Weather,'disableColoredTemp', registry.Boolean(False, """If disableANSI is True, this will color temperatures based on values."""))
conf.registerGlobalValue(Weather,'forecast', registry.Boolean(True, ("""Display forecast in output by default?"""))) conf.registerGlobalValue(Weather,'forecast', registry.Boolean(True, ("""Display forecast in output by default?""")))
conf.registerGlobalValue(Weather,'forecastDays', registry.Integer(1, ("""How many days of forecast to display. One is good."""))) conf.registerGlobalValue(Weather,'forecastDays', registry.Integer(1, ("""How many days of forecast to display. One is good.""")))
conf.registerGlobalValue(Weather,'alerts', registry.Boolean(False, ("""Display alerts by default?"""))) conf.registerGlobalValue(Weather,'alerts', registry.Boolean(False, ("""Display alerts by default?""")))
conf.registerGlobalValue(Weather,'almanac', registry.Boolean(False, ("""Display almanac by default?"""))) conf.registerGlobalValue(Weather,'almanac', registry.Boolean(False, ("""Display almanac by default?""")))
conf.registerGlobalValue(Weather,'astronomy', registry.Boolean(False, ("""Display astronomy by default?"""))) conf.registerGlobalValue(Weather,'astronomy', registry.Boolean(False, ("""Display astronomy by default?""")))
conf.registerGlobalValue(Weather,'hourly', registry.Boolean(False, ("""Display hourly by default?""")))
conf.registerGlobalValue(Weather,'showPressure', registry.Boolean(False, ("""Show pressure in output?"""))) conf.registerGlobalValue(Weather,'showPressure', registry.Boolean(False, ("""Show pressure in output?""")))
conf.registerGlobalValue(Weather,'showWind', registry.Boolean(False, ("""Show wind in output?"""))) conf.registerGlobalValue(Weather,'showWind', registry.Boolean(False, ("""Show wind in output?""")))
conf.registerGlobalValue(Weather,'lang', registry.String('EN', ("""language to use. See docs for available codes."""))) conf.registerGlobalValue(Weather,'lang', registry.String('EN', ("""language to use. See docs for available codes.""")))

View File

@ -216,7 +216,7 @@ class Weather(callbacks.Plugin):
return False return False
# urlargs will be used to build the url to query the API. # urlargs will be used to build the url to query the API.
urlArgs = {'features':['conditions'], urlArgs = {'features':['conditions','forecast'],
'lang':self.registryValue('lang'), 'lang':self.registryValue('lang'),
'bestfct':'1', 'bestfct':'1',
'pws':'0' 'pws':'0'
@ -224,7 +224,6 @@ class Weather(callbacks.Plugin):
# now, start our dict for output formatting. # now, start our dict for output formatting.
args = {'imperial':self.registryValue('useImperial', msg.args[0]), args = {'imperial':self.registryValue('useImperial', msg.args[0]),
'alerts':self.registryValue('alerts'), 'alerts':self.registryValue('alerts'),
'forecast':self.registryValue('forecast'),
'forecastDays':self.registryValue('forecastDays'), 'forecastDays':self.registryValue('forecastDays'),
'almanac':self.registryValue('almanac'), 'almanac':self.registryValue('almanac'),
'astronomy':self.registryValue('astronomy'), 'astronomy':self.registryValue('astronomy'),
@ -256,8 +255,6 @@ class Weather(callbacks.Plugin):
args['imperial'] = False args['imperial'] = False
if key == 'alerts': if key == 'alerts':
args['alerts'] = True args['alerts'] = True
if key == 'forecast':
args['forecast'] = True
if key == 'days': if key == 'days':
args['forecastDays'] = value args['forecastDays'] = value
if key == 'almanac': if key == 'almanac':
@ -277,7 +274,7 @@ class Weather(callbacks.Plugin):
# urlArgs['features'] also manipulated via what's in args. # urlArgs['features'] also manipulated via what's in args.
url = 'http://api.wunderground.com/api/%s/' % (self.APIKEY) # first part of url, w/APIKEY url = 'http://api.wunderground.com/api/%s/' % (self.APIKEY) # first part of url, w/APIKEY
# now we need to set certain things for urlArgs based on args. # now we need to set certain things for urlArgs based on args.
for check in ['alerts','forecast','almanac']: for check in ['alerts','almanac']:
if args[check]: # if args['value'] is True, either via config or getopts. if args[check]: # if args['value'] is True, either via config or getopts.
urlArgs['features'].append(check) # append to dict->key (list) urlArgs['features'].append(check) # append to dict->key (list)
# now, we use urlArgs dict to append to url. # now, we use urlArgs dict to append to url.
@ -329,15 +326,23 @@ class Weather(callbacks.Plugin):
outdata['humidity'] = data['current_observation']['relative_humidity'] outdata['humidity'] = data['current_observation']['relative_humidity']
outdata['uv'] = data['current_observation']['UV'] outdata['uv'] = data['current_observation']['UV']
# handle wind. # handle wind. check if there is none first.
if args['imperial']: if args['imperial']:
if data['current_observation']['wind_mph'] is 0: # no wind.
outdata['wind'] = "No wind."
else:
outdata['wind'] = "{0} at {1}mph. Gusts to {2}mph".format(\ outdata['wind'] = "{0} at {1}mph. Gusts to {2}mph".format(\
data['current_observation']['wind_dir'],data['current_observation']['wind_mph'],data['current_observation']['wind_gust_mph']) data['current_observation']['wind_dir'],data['current_observation']['wind_mph'],\
data['current_observation']['wind_gust_mph'])
else:
if data['current_observation']['wind_kph'] is 0: # no wind.
outdata['wind'] = "No wind."
else: else:
outdata['wind'] = "{0} at {1}kph. Gusts to {2}kph".format(\ outdata['wind'] = "{0} at {1}kph. Gusts to {2}kph".format(\
data['current_observation']['wind_dir'],data['current_observation']['wind_kph'],data['current_observation']['wind_gust_kph']) data['current_observation']['wind_dir'],data['current_observation']['wind_kph'],\
data['current_observation']['wind_gust_kph'])
# handle the time. many elements from WunderWeather here. # handle the time. concept/method from WunderWeather plugin.
observationTime = data['current_observation'].get('observation_epoch', None) observationTime = data['current_observation'].get('observation_epoch', None)
localTime = data['current_observation'].get('local_epoch', None) localTime = data['current_observation'].get('local_epoch', None)
if not observationTime or not localTime: # if we don't have the epoches from above, default to obs_time if not observationTime or not localTime: # if we don't have the epoches from above, default to obs_time
@ -376,24 +381,17 @@ class Weather(callbacks.Plugin):
outdata['visibility'] = str(data['current_observation']['visibility_km']) + 'km' outdata['visibility'] = str(data['current_observation']['visibility_km']) + 'km'
# handle forecast data part. output will be below. # handle forecast data part. output will be below.
if args['forecast']:
forecastdata = {} # dict to store data in. forecastdata = {} # dict to store data in.
for forecastday in data['forecast']['txt_forecast']['forecastday']: for forecastday in data['forecast']['txt_forecast']['forecastday']:
tmpdict = {} tmpdict = {}
tmpdict['day'] = forecastday['title'] tmpdict['day'] = forecastday['title']
if args['imperial']: if args['imperial']:
tmpdict['text'] = forecastday['fcttext'] fcttext_metric tmpdict['text'] = forecastday['fcttext']
else: else:
tmpdict['text'] = forecastday['fcttext_metric'] tmpdict['text'] = forecastday['fcttext_metric']
forecastdata[int(forecastday['period'])] = tmpdict forecastdata[int(forecastday['period'])] = tmpdict
# now, lets output what we have. # now, build output object with what to output.
# Weather for Nashua, NH | Temperature: 27°F / -3°F (Wind Chill: 12°F / -11°C);
# Humidity: 64%; Conditions: Light snow mist; Wind: Nw, 24mph / 39kph; Updated: 12 mins, 37 secs ago
# Forecast for Sunday: Partly cloudy; High of 28°F / -2°C; Low of 12°F / -11°C
# Atlanta, GA (observed 4s ago @ 1050 ft - Sun: 7:42/17:38, Moon: 95%): Temp: 37.9°F/3.3°C
# Windchill: 33°F/0°C Humidity: 47% Conditions: Clear Wind: WNW @ 7.0mph/11.3kmh
# (7.0mph/11.3kmh gusts) Visibility: 10.0mi/16.1km Record High (1996): 69°F/20.6°C Record Low (2000): 19°F/-7.2°C
output = "Weather for {0} :: {1} (Feels like: {2}) | {3} {4}".format(\ output = "Weather for {0} :: {1} (Feels like: {2}) | {3} {4}".format(\
self._bold(outdata['location']),self._temp(outdata['temp']),self._temp(outdata['feelslike']),\ self._bold(outdata['location']),self._temp(outdata['temp']),self._temp(outdata['feelslike']),\
self._bold('Conditions:'), outdata['weather']) self._bold('Conditions:'), outdata['weather'])
@ -411,6 +409,9 @@ class Weather(callbacks.Plugin):
if v: # if that key's value is True if v: # if that key's value is True
output += " | {0}: {1}".format(self._bold(k.title()), outdata[k]) output += " | {0}: {1}".format(self._bold(k.title()), outdata[k])
# add in the first forecast item in conditions.
output += " | {0} {1}".format(self._bold(forecastdata[0]['day']),forecastdata[0]['text'])
# finally, add the time and output. # finally, add the time and output.
output += " | {0} {1}".format(self._bold('Updated:'), outdata['observation']) output += " | {0} {1}".format(self._bold('Updated:'), outdata['observation'])
irc.reply(output.encode('utf-8')) irc.reply(output.encode('utf-8'))
@ -445,12 +446,10 @@ class Weather(callbacks.Plugin):
temphighnormal,temphighrecord,temphighyear,\ temphighnormal,temphighrecord,temphighyear,\
templownormal, templowrecord, templowyear)) templownormal, templowrecord, templowyear))
if args['forecast']:
pass
wunderground = wrap(wunderground, [getopts({'alerts':'', wunderground = wrap(wunderground, [getopts({'alerts':'',
'almanac':'', 'almanac':'',
'astronomy':'', 'astronomy':'',
'forecast':'',
'days':('int'), 'days':('int'),
'pressure':'', 'pressure':'',
'wind':'', 'wind':'',