Merge lp:~saiarcot895/my-weather-indicator/time-zone-fix into lp:my-weather-indicator

Proposed by Saikrishna Arcot
Status: Merged
Approved by: Lorenzo Carbonell
Approved revision: 195
Merged at revision: 195
Proposed branch: lp:~saiarcot895/my-weather-indicator/time-zone-fix
Merge into: lp:my-weather-indicator
Diff against target: 53 lines (+11/-12)
2 files modified
debian/control (+1/-1)
src/geocodeapi.py (+10/-11)
To merge this branch: bzr merge lp:~saiarcot895/my-weather-indicator/time-zone-fix
Reviewer Review Type Date Requested Status
Lorenzo Carbonell Approve
Review via email: mp+173313@code.launchpad.net

Description of the change

Change the time zone provider to Geonames, which returns a time zone compatible with Olson's time zone database, and use python-tz to look up the UTC offset.

To post a comment you must log in.
Revision history for this message
Lorenzo Carbonell (lorenzo-carbonell) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-04-20 06:50:43 +0000
3+++ debian/control 2013-07-06 14:30:35 +0000
4@@ -2,7 +2,7 @@
5 Section: utils
6 Priority: extra
7 Maintainer: Lorenzo Carbonell Cerezo <lorenzo.carbonell.cerezo@gmail.com>
8-Build-Depends: debhelper (>= 8), python, python-distutils-extra, python-polib
9+Build-Depends: debhelper (>= 8), python, python-distutils-extra, python-polib, python3-tz, python3-urllib3,
10 Standards-Version: 3.9.3
11 Homepage: http://www.atareao.es
12
13
14=== modified file 'src/geocodeapi.py'
15--- src/geocodeapi.py 2013-05-19 21:57:34 +0000
16+++ src/geocodeapi.py 2013-07-06 14:30:35 +0000
17@@ -28,6 +28,8 @@
18 from sun import Sun
19 import locale
20 import datetime
21+import pytz
22+import urllib
23 locale.setlocale(locale.LC_MESSAGES, '')
24 LANG = locale.getlocale(locale.LC_MESSAGES)[0]
25 '''
26@@ -99,19 +101,16 @@
27 if len(directions)>0:
28 return directions[0]
29 return None
30-
31
32 def get_rawOffset(lat,lon):
33- url = 'http://www.earthtools.org/timezone/%s/%s'%(lat,lon)
34- response = read_from_url(url).decode('ISO-8859-1')
35- inicio = response.find('<offset>')+8
36- fin = response.find('</offset>')
37- ro = s2f(response[inicio:fin])
38- inicio = response.find('<dst>')+5
39- fin = response.find('</dst>')
40- if response[inicio:fin]=='True':
41- ro = ro + 1.0
42- return ro
43+ try:
44+ response = read_from_url('http://api.geonames.org/timezoneJSON?lat=%s&lng=%s&username=saiarcot895'%(lat,lon)).decode('ISO-8859-1')
45+ json_response = json.loads(response)
46+ timezone = pytz.timezone(json_response['timezoneId']);
47+ strOffset = timezone.localize(datetime.datetime.now()).strftime("%z");
48+ return s2f(strOffset) / 100;
49+ except urllib.error.URLError:
50+ print('Geonames error')
51
52 def get_inv_direction(lat,lon):
53 directions = get_inv_directions(lat,lon)

Subscribers

People subscribed via source and target branches

to status/vote changes: