def get_location_data_for(ip):
if not ip:
return {}
# Check the common private IP spaces (used by Google for sending requests)
if IPy.IP(ip).iptype() == 'PRIVATE':
return {}
start = time.time()
data = _get_cache(ip)
timelog.log_time_since('Getting IP Cache', start)
if not data:
#TODO: consider using http://geoiplookup.net/ , which might offer better granularity/resolution
url = 'http://freegeoip.net/json/%s' % ip
start = time.time()
results = urllib.urlopen(url).read()
timelog.log_time_since('Getting IPData', start)
data = json.loads(results)
start = time.time()
_save_cache(ip, data)
timelog.log_time_since('Saving IPCache', start)
return data
评论列表
文章目录