Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tree: 238cec1b3f
Fetching contributors…

Cannot retrieve contributors at this time

executable file 52 lines (46 sloc) 1.568 kB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2011 by Florian Mounier, Kozea
# This file is part of pystil, licensed under a 3-clause BSD license.
from pystil import config
from pystil.corns import Visit
from pygeoip import GeoIP, MMAP_CACHE
import re
gip = GeoIP(config.CONFIG['IP_DB'], MMAP_CACHE)
IPV4RE = re.compile(r"(\d{1,3}(\.|$)){4}")
for visit in Visit.all.execute():
lat = None
lng = None
country_code = None
ip = visit['ip']
ip = ip.replace('::ffff:', '')
if IPV4RE.match(ip):
if (ip == ''
or ip.startswith('192.168.')
or ip.startswith('10.')):
city = 'Local'
country = 'Local'
location = gip.record_by_addr(ip)
city = (location.get('city', 'Unknown')
if location else 'Unknown')
country = (location.get('country_name', 'Unknown')
if location else 'Unknown')
country_code = (location.get('country_code', 'Unknown')
if location else 'Unknown')
lat = location.get('latitude', None)
lng = location.get('longitude', None)
country = 'ipv6'
city = 'ipv6'
visit['country'] = country
visit['country_code'] = country_code
visit['city'] = city
visit['lat'] = lat
visit['lng'] = lng
print city, " done"
Jump to Line
Something went wrong with that request. Please try again.