How to use the geoip2.models.City function in geoip2

To help you get started, we’ve selected a few geoip2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zentralopensource / zentral / zentral / core / events / base.py View on Github external
def build_from_city(cls, c):
        if not isinstance(c, City):
            raise TypeError("not a geoip2.records.City object")
        kwargs = {}
        if c.city.name:
            kwargs["city_name"] = c.city.name
        if c.continent.name:
            kwargs["continent_name"] = c.continent.name
        if c.country.iso_code:
            kwargs["country_iso_code"] = c.country.iso_code
        if c.country.name:
            kwargs["country_name"] = c.country.name
        if c.location.longitude is not None and c.location.latitude is not None:
            kwargs["location"] = {"lat": c.location.latitude,
                                  "lon": c.location.longitude}
        if c.subdivisions.most_specific.iso_code:
            kwargs["region_iso_code"] = c.subdivisions.most_specific.iso_code
        if c.subdivisions.most_specific.name:
github maxmind / GeoIP2-python / geoip2 / webservice.py View on Github external
def city(self, ip_address='me'):
        """Call GeoIP2 Precision City endpoint with the specified IP.

        :param ip_address: IPv4 or IPv6 address as a string. If no
           address is provided, the address that the web service is
           called from will be used.

        :returns: :py:class:`geoip2.models.City` object

        """
        return self._response_for('city', geoip2.models.City, ip_address)
github maxmind / GeoIP2-python / geoip2 / models.py View on Github external
def __init__(self, raw_response, locales=None):
        super(City, self).__init__(raw_response, locales)
        self.city = \
            geoip2.records.City(locales, **raw_response.get('city', {}))
        self.location = \
            geoip2.records.Location(**raw_response.get('location', {}))
        self.postal = \
            geoip2.records.Postal(**raw_response.get('postal', {}))
        self.subdivisions = \
            geoip2.records.Subdivisions(locales,
                                        *raw_response.get('subdivisions', []))
github maxmind / GeoIP2-python / geoip2 / models.py View on Github external
Object (tuple) representing the subdivisions of the country to which
      the location of the requested IP address belongs.

      :type: :py:class:`geoip2.records.Subdivisions`

    .. attribute:: traits

      Object with the traits of the requested IP address.

      :type: :py:class:`geoip2.records.Traits`

    """


class Enterprise(City):
    """Model for the GeoIP2 Enterprise database.

    .. attribute:: city

      City object for the requested IP address.

      :type: :py:class:`geoip2.records.City`

    .. attribute:: continent

      Continent object for the requested IP address.

      :type: :py:class:`geoip2.records.Continent`

    .. attribute:: country
github maxmind / GeoIP2-python / geoip2 / database.py View on Github external
def city(self, ip_address):
        """Get the City object for the IP address.

        :param ip_address: IPv4 or IPv6 address as a string.

        :returns: :py:class:`geoip2.models.City` object

        """
        return self._model_for(geoip2.models.City, 'City', ip_address)
github maxmind / GeoIP2-python / geoip2 / models.py View on Github external
"""
    def __init__(self, raw_response, locales=None):
        super(City, self).__init__(raw_response, locales)
        self.city = \
            geoip2.records.City(locales, **raw_response.get('city', {}))
        self.location = \
            geoip2.records.Location(**raw_response.get('location', {}))
        self.postal = \
            geoip2.records.Postal(**raw_response.get('postal', {}))
        self.subdivisions = \
            geoip2.records.Subdivisions(locales,
                                        *raw_response.get('subdivisions', []))


class Insights(City):
    """Model for the GeoIP2 Precision: Insights web service endpoint.

    .. attribute:: city

      City object for the requested IP address.

      :type: :py:class:`geoip2.records.City`

    .. attribute:: continent

      Continent object for the requested IP address.

      :type: :py:class:`geoip2.records.Continent`

    .. attribute:: country