#!/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 """
""" % (width, height, width, width, height, height/2, width/2, ) import math for (key, value) in cityFreq.iteritems(): size = math.ceil(math.sqrt(cityFreq[key] / math.pi) * 5) offsetLeft = size / 2.0 offsetBottom = size / 2.0 print '' % ((location[key][1]*width/360) - offsetLeft, (location[key][0]*height/180) - offsetBottom, 1000-cityFreq[key], key, cityFreq[key], locatordot%size, size, size) print """
""" 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 '' print '' for key, value in sorted(cityFreq.items()): print ''%(key, value) print '
Country-RegionUsers
%s%s
' if __name__ == "__main__" : print "Content-Type: text/html; charset=UTF-8\n" main() #import wikipedia #if __name__ == "__main__" and wikipedia.handleUrlAndHeader(): # try: # wikipedia.startContent(form=False) # main() # finally: # wikipedia.endContent() # wikipedia.stopme()