ip_geolocation.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:dancedeets-monorepo 作者: mikelambert 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号