|
| 1 | +from __future__ import absolute_import |
| 2 | + |
| 3 | +from geocoder.geonames import GeonamesQuery, GeonamesResult |
| 4 | +from geocoder.location import Location |
| 5 | + |
| 6 | + |
| 7 | +class GeonamesTimezoneResult(GeonamesResult): |
| 8 | + """ Get timezone information for given lat,lng""" |
| 9 | + |
| 10 | + @property |
| 11 | + def sunrise(self): |
| 12 | + return self.raw.get('sunrise') |
| 13 | + |
| 14 | + @property |
| 15 | + def gmt_offset(self): |
| 16 | + return self.raw.get('gmtOffset') |
| 17 | + |
| 18 | + @property |
| 19 | + def raw_offset(self): |
| 20 | + return self.raw.get('rawOffset') |
| 21 | + |
| 22 | + @property |
| 23 | + def dst_offest(self): |
| 24 | + return self.raw.get('dstOffset') |
| 25 | + |
| 26 | + @property |
| 27 | + def sunset(self): |
| 28 | + return self.raw.get('sunset') |
| 29 | + |
| 30 | + @property |
| 31 | + def timezone_id(self): |
| 32 | + return self.raw.get('timezoneId') |
| 33 | + |
| 34 | + @property |
| 35 | + def time(self): |
| 36 | + return self.raw.get('time') |
| 37 | + |
| 38 | + |
| 39 | +class GeonamesTimezone(GeonamesQuery): |
| 40 | + """ Details: |
| 41 | + http://api.geonames.org/timezoneJSON?lat=47.01&lng=10.2 |
| 42 | + """ |
| 43 | + |
| 44 | + provider = 'geonames' |
| 45 | + method = 'timezone' |
| 46 | + |
| 47 | + _URL = 'http://api.geonames.org/timezoneJSON' |
| 48 | + _RESULT_CLASS = GeonamesTimezoneResult |
| 49 | + |
| 50 | + def _build_params(self, location, provider_key, **kwargs): |
| 51 | + """Will be overridden according to the targetted web service""" |
| 52 | + location = Location(location) |
| 53 | + return { |
| 54 | + 'lat': location.latitude, |
| 55 | + 'lng': location.longitude, |
| 56 | + 'username': provider_key |
| 57 | + } |
| 58 | + |
| 59 | + def _adapt_results(self, json_response): |
| 60 | + # the returned JSON contains the object. |
| 61 | + # Need to wrap it into an array |
| 62 | + return [json_response] |
0 commit comments