#!/usr/bin/python
import cgi
import GeoIP
import MySQLdb
import cgitb; cgitb.enable()
def main():
form = cgi.FieldStorage()
dbName = form.getfirst('dbname', 'enwiki')
locatordot = "http://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/Blue_pog.svg/%dpx-Blue_pog.svg.png"
#locatordot = "http://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/White_pog.svg/64px-White_pog.svg.png"
#locatordot = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Cercle_rouge_100%25.svg/200px-Cercle_rouge_100%25.svg.png"
height = 500
width = 1000
gc=GeoIP.open('/home/gmaxwell/GeoLiteCity.dat',GeoIP.GEOIP_STANDARD)
db = MySQLdb.connect(db=dbName+'_p', host=dbName.replace('_', '-') + '-p.db.toolserver.org', read_default_file="/home/dispenser/.my.cnf")
c = db.cursor()
c.execute('SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED')
c.execute('SELECT DISTINCT rc_user_text FROM recentchanges WHERE rc_timestamp >= now() - INTERVAL 1 HOUR AND rc_user = 0 AND rc_bot!=1')
cityFreq = {}
location = {}
totalrows = 0
located = 0
for (ipaddr,) in c.fetchall():
totalrows += 1
lookup=gc.record_by_addr(ipaddr)
#print lookup
#print '
'
if not lookup: continue
else: located += 1
key = "%s-%s"% (lookup.get('country_code', ''), None)#lookup.get('region'))
if key not in cityFreq:
cityFreq[key] = 1
else:
cityFreq[key] += 1
location[key] = lookup['latitude'], lookup['longitude']
c.close()
print """
Showing the Regional locations of %d IP addresses (%d not located) which edited Wikipedia (%s) in the last hour.
'%(located, totalrows-located, dbName) print '| Country-Region | Users |
|---|---|
| %s | %s |