Esempio n. 1
0
    def find_geo_location(self):
        gi = pygeoip.GeoIP(self.db_path, db_contents=self.geo_db_contents)
        try:
            self.success = True
            result = gi.record_by_addr(self.ip)

            if 'country_name' in result:
                self.country = unicode(result['country_name'])
                self.country_code = result['country_code']

            if 'region_name' in result:
                self.state = get_region_name(result['country_code'], result['region_name'])
                self.region_name = result['region_name']

            if 'city' in result:
                self.city = result['city'].decode('ISO-8859-1').encode('utf8')

            if 'latitude' in result:
                self.latitude = result['latitude']

            if 'longitude' in result:
                self.longitude = result['longitude']

        except Exception, err:
            self.success = False
            logging.info("Geolocation for ip %s could not be retrieved. Error: %s" % (self.ip, str(err)))
Esempio n. 2
0
    def find_geo_location(self):
        gi = pygeoip.GeoIP(self.db_path, db_contents=self.geo_db_contents)
        try:
            self.success = True
            result = gi.record_by_addr(self.ip)

            if 'country_name' in result:
                self.country = unicode(result['country_name'])
                self.country_code = result['country_code']

            if 'region_name' in result:
                self.state = get_region_name(result['country_code'],
                                             result['region_name'])
                self.region_name = result['region_name']

            if 'city' in result:
                self.city = result['city'].decode('ISO-8859-1').encode('utf8')

            if 'latitude' in result:
                self.latitude = result['latitude']

            if 'longitude' in result:
                self.longitude = result['longitude']

        except Exception, err:
            self.success = False
            logging.info(
                "Geolocation for ip %s could not be retrieved. Error: %s" %
                (self.ip, str(err)))
Esempio n. 3
0
    def test_getting_br_region(self):
        region_name = get_region_name('BR', '27')

        assert region_name == u'São Paulo'