Example #1
0
    def handle(self, *args, **options):
        # Q(country__isnull=True) | Q(lat__isnull=True)
        for ip in IpAddress.objects.all():
            try:
                f = urlopen(api_url % ip.ip)
                raw_response = f.read().decode("utf-8")
                response = json.loads(raw_response)
                if response['status'] != "success":
                    raise Exception(response['status'])
                ip.country_code = response['countryCode']
                ip.isp = response['isp']
                ip.country = response['country']
                ip.region = response['regionName']
                ip.city = response['city']
                ip.country_code = response['countryCode']
                ip.lat = response['lat']
                ip.lon = response['lon']
                ip.timezone = response['timezone']
                ip.zip = response['zip']

                ip.save()
                print("Saved %s" % raw_response)
                time.sleep(5)  # do not get banned
            except Exception as e:
                print("Skip %s because %s" % (ip, e))
Example #2
0
 def download_http_photo(self, url, user_profile):
     if url is not None:
         try:
             response = urlopen(url)
             filename = get_random_path(None, url.split('/')[-1])
             content = ContentFile(response.read())
             user_profile.photo.save(filename, content, False)
         except Exception as e:
             self.logger.error(
                 "Unable to download photo from url %s for user %s because %s",
                 url, user_profile.username, e)
	def handle(self, *args, **options):
		for ip in IpAddress.objects.all():
			try:
				f = urlopen(api_url % ip.ip)
				raw_response = f.read().decode("utf-8")
				response = json.loads(raw_response)
				if response['status'] != "success":
					raise Exception(response['status'])
				ip.country_code = response['countryCode']
				ip.isp = response['isp'],
				ip.country = response['country'],
				ip.region = response['regionName'],
				ip.city = response['city'],
				ip.country_code = response['countryCode']
				ip.save()
			except Exception as e:
				print("Skip %s because %s" % (ip, e))
Example #4
0
	def create_ip():
		f = urlopen(settings.IP_API_URL % ip)
		decode = f.read().decode("utf-8")
		return create_ip_structure(ip, decode)