1 # -*- coding: utf-8 -*-
3 import urllib2, gzip, base64
4 from StringIO import StringIO
6 WAIK = 'NDEzNjBkMjFkZjFhMzczNg=='
7 WUNDERGROUND_URL = 'http://api.wunderground.com/api/%s/%s/%s/q/%s.%s'
8 API_EXCLUDE = ['hourly10day', 'yesterday', 'planner', 'webcams', 'animatedradar', 'animatedsatellite', 'currenthurricane']
10 def wundergroundapi(features, settings, query, format):
13 wunderground api module
17 1) import the wunderground addon in your addon.xml:
19 <import addon="weather.wunderground" version="0.1.12"/>
22 2) import the wunderground api module in your script:
23 from wunderground import wundergroundapi
25 3) to fetch weather data:
26 weatherdata = wundergroundapi(features, settings, query, format)
28 see http://www.wunderground.com/weather/api/d/docs?d=data/index
29 for api features, optional settings, query examples and response formats.
32 for item in API_EXCLUDE:
34 return 'api access to %s restricted' % item
37 url = WUNDERGROUND_URL % (base64.b64decode(WAIK)[::-1], features, settings, query, format)
39 req = urllib2.Request(url)
40 req.add_header('Accept-encoding', 'gzip')
41 response = urllib2.urlopen(req)
42 if response.info().get('Content-Encoding') == 'gzip':
43 buf = StringIO(response.read())
44 compr = gzip.GzipFile(fileobj=buf)
47 data = response.read()