City/Date tracker

From XPUB & Lens-Based wiki

This script gives a date and location of the person that visited the website with a certain extension/key. <source lang="python">

import cgitb, cgi cgitb.enable()

print "Content-type: text/html" print

import sys, datetime, urllib


something = {'first': ['Berlin','08/03/12'], 'second': ['Amsterdam', '16/03/12'], 'third':['Den Haag', '30/04/12']}


allarguments = cgi.FieldStorage() key = allarguments["key"].value result= something[key]

mypart1= result[0] mypart2= result[1]

from datetime import datetime d=datetime.now() timeday= d.strftime("%d/%m/%y")

from urllib import urlopen import json ip = urlopen('http://automation.whatismyip.com/n09230945.asp').read() response = urllib.urlopen('http://freegeoip.net/json/'+ip) allinfo = json.load(response) city= allinfo['city']


print """ <html>

<head> </head>

<body>

{0}, {1} ------------------------------------------ {3}, {2}

</body>

</html> """.format(mypart1, mypart2, timeday, city, )