site_stats.py 文件源码

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

项目:FRG-Crowdsourcing 作者: 97amarnathk 项目源码 文件源码
def get_locs():
    """Return locations (latitude, longitude) for anonymous users."""
    # All IP addresses from anonymous users
    locs = []
    if current_app.config['GEO']:
        sql = '''SELECT DISTINCT(user_ip) FROM task_run
                 WHERE user_ip IS NOT NULL;'''
        results = session.execute(sql)

        geolite = current_app.root_path + '/../dat/GeoLiteCity.dat'
        gic = pygeoip.GeoIP(geolite)
        for row in results:
            loc = gic.record_by_addr(row.user_ip)
            if loc is None:
                loc = {}
            if (len(loc.keys()) == 0):
                loc['latitude'] = 0
                loc['longitude'] = 0
            locs.append(dict(loc=loc))
    return locs
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号