Using geoip2 to create a timezone

The framework django.contrib.gis.geoip2

provides a high level of geolocation api. I want to use it to find the user's timezone, but the queries do not return the timezone, although the maxmind documetion says their databases include them. Am I missing something or how can this be done?

+3


source to share


2 answers


Looks like it time_zone

is a class field geoip2.records.Location

in the MaxMind GeoIP2 API.

In Django wrapper, the response is defined here and does not forward the field time_zone

.

You can add a line to the wrapper that is simply:



    'time_zone': response.location.time_zone,

      

I'm sure they'll appreciate the pull request. :)

+3


source


The following class overrides the class GeoIP2

to display time zone information. Might be useful until it is added to the base class (it will try to raise PR for it shortly if no one gets it first)



from django.contrib.gis.geoip2 import GeoIP2


class GeoipWithTimezone(GeoIP2):
    def timezone(self, query):
        enc_query = self._check_query(query, city=True)
        return self._city.city(enc_query).location.time_zone

      

+1


source







All Articles