@@ -36,6 +36,7 @@ def __init__(self, plugin_spec):
3636 AbstractMessagePlugin .__init__ (self , plugin_spec , True )
3737 self .define_property ('city' )
3838 self .define_property ('units' , required = False , default = 'imperial' )
39+ self .define_property ('appid' , required = False )
3940 self .share_property ('tz' , plugin_spec = timezone .PLUGIN_SPEC )
4041 ## plugin uses location_location from Location plugin
4142 self .share_property ('location_location' )
@@ -60,8 +61,12 @@ def addcontext(self, message_file, config):
6061 message_file .write ('Couldn\' t determine city to fetch weather.\n ' )
6162 return False
6263
64+ if self .appid == None :
65+ message_file .write ('Open Weather Map requires an API key. For more information see: https://github.com/commandline/flashbake/wiki/Plugins' )
66+ return False
67+
6368 # call the open weather map API with the city
64- weather = self .__getweather (city , self .units )
69+ weather = self .__getweather (city , self .appid , self . units )
6570
6671 if len (weather ) > 0 :
6772 message_file .write ('Current weather for %(city)s: %(description)s. %(temp)i%(temp_units)s. %(humidity)s%% humidity\n '
@@ -70,12 +75,12 @@ def addcontext(self, message_file, config):
7075 message_file .write ('Couldn\' t fetch current weather for city, %s.\n ' % city )
7176 return len (weather ) > 0
7277
73- def __getweather (self , city , units = 'imperial' ):
78+ def __getweather (self , city , appid , units = 'imperial' ):
7479 """ This relies on Open Weather Map's API which may change without notice. """
7580
7681 baseurl = 'http://api.openweathermap.org/data/2.5/weather?'
7782 # encode the parameters
78- for_city = baseurl + urllib .urlencode ({'q' : city , 'units' : units })
83+ for_city = baseurl + urllib .urlencode ({'q' : city , 'units' : units , 'appid' : appid })
7984
8085 try :
8186 logging .debug ('Requesting page for %s.' % for_city )
0 commit comments