diff options
author | ronie <ronie@poedel.net> | 2012-02-09 23:07:39 +0100 |
---|---|---|
committer | ronie <ronie@poedel.net> | 2012-02-09 23:07:39 +0100 |
commit | d1abd6954ab9f85b7d164ed2a45911604204abf6 (patch) | |
tree | d7ea352989604f05ffc2347676203fcf128415b7 /addons | |
parent | f0aadd360c17fb501bbe10fb245ded1c9f59a0a6 (diff) |
add geoip support and fetch 7 day forecast
Diffstat (limited to 'addons')
-rw-r--r-- | addons/weather.wunderground/addon.xml | 2 | ||||
-rw-r--r-- | addons/weather.wunderground/changelog.txt | 5 | ||||
-rw-r--r-- | addons/weather.wunderground/default.py | 24 |
3 files changed, 25 insertions, 6 deletions
diff --git a/addons/weather.wunderground/addon.xml b/addons/weather.wunderground/addon.xml index ee79a9f304..06e5deb593 100644 --- a/addons/weather.wunderground/addon.xml +++ b/addons/weather.wunderground/addon.xml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" standalone="yes"?> -<addon id="weather.wunderground" name="Weather Underground" version="0.0.4" provider-name="Team XBMC"> +<addon id="weather.wunderground" name="Weather Underground" version="0.0.5" provider-name="Team XBMC"> <requires> <import addon="xbmc.python" version="2.0"/> <import addon="script.module.simplejson" version="2.0.10"/> diff --git a/addons/weather.wunderground/changelog.txt b/addons/weather.wunderground/changelog.txt index d4ce40b10f..62596ec82e 100644 --- a/addons/weather.wunderground/changelog.txt +++ b/addons/weather.wunderground/changelog.txt @@ -1,3 +1,8 @@ +v0.0.5 +- add geoip support +- fetch 7 day forecast +- workaround: when user switches weather addon, xbmc may call the script with a location id that has not been setup. try to fallback to id 1 in this case. + v0.0.4 - don't fetch weather when no locations are set up - fix incrementing values on each weather refresh when no locations are set up diff --git a/addons/weather.wunderground/default.py b/addons/weather.wunderground/default.py index c00e6d3ac6..86d07c70a0 100644 --- a/addons/weather.wunderground/default.py +++ b/addons/weather.wunderground/default.py @@ -28,8 +28,10 @@ from utilities import * LOCATION_URL = 'http://autocomplete.wunderground.com/aq?query=%s&format=JSON' WEATHER_URL = 'http://api.wunderground.com/api/%s/conditions/forecast7day/hourly%s.json' +GEOIP_URL = 'http://api.wunderground.com/api/%s/geolookup/q/autoip.json' A_I_K = 'NDEzNjBkMjFkZjFhMzczNg==' WEATHER_WINDOW = xbmcgui.Window(12600) +MAXDAYS = 6 socket.setdefaulttimeout(10) @@ -82,6 +84,16 @@ def location(string): locid.append(locationid) return loc, locid +def geoip(): + data = fetch(GEOIP_URL % aik[::-1]) + if data != '' and data.has_key('location'): + location = data['location']['l'] + __addon__.setSetting('Location1', data['location']['city']) + __addon__.setSetting('Location1id', location) + else: + location = '' + return location + def forecast(city): data = fetch(WEATHER_URL % (aik[::-1], city)) if data != '': @@ -108,7 +120,7 @@ def properties(query): set_property('Day%i.Outlook' % count, item['conditions']) set_property('Day%i.OutlookIcon' % count, '%s.png' % weathercode) set_property('Day%i.FanartCode' % count, weathercode) - if count == 3: + if count == MAXDAYS: break if sys.argv[1].startswith('Location'): @@ -129,9 +141,12 @@ if sys.argv[1].startswith('Location'): else: location = __addon__.getSetting('Location%sid' % sys.argv[1]) aik = base64.b64decode(A_I_K) + if (location == '') and (sys.argv[1] != '1'): + location = __addon__.getSetting('Location1id') + if location == '': + location = geoip() if not location == '': forecast(location) - refresh_locations() else: # workaround to fix incrementing values on each weather refresh when no locations are set up: set_property('Current.Condition' , 'N/A') @@ -144,14 +159,13 @@ else: set_property('Current.DewPoint' , '0') set_property('Current.OutlookIcon' , 'na.png') set_property('Current.FanartCode' , 'na') - for count in range (0, 3): + for count in range (0, MAXDAYS): set_property('Day%i.Title' % count, 'N/A') set_property('Day%i.HighTemp' % count, '0') set_property('Day%i.LowTemp' % count, '0') set_property('Day%i.Outlook' % count, 'N/A') set_property('Day%i.OutlookIcon' % count, 'na.png') set_property('Day%i.FanartCode' % count, 'na') - # workaround to stop xbmc from running the script in a loop when no locations are set up: - set_property('Locations', '1') +refresh_locations() set_property('WeatherProvider', 'Weather Underground') |