from flask import Flask
from flask import request
from time import strftime, time
import os
sites = {"1":"trackedsite.com"}
app = Flask(__name__)
@app.route("/t", methods=['GET'])
def track():
def rargs(arg):
args = request.args
return args[arg] if arg in args else "null"
def nullwrap(arg):
return arg if arg != None else "null"
sitename = sites[request.args['s']]
day = strftime("%D").replace("/","-")
folder = "/var/trackingdata/"
filename = folder + sitename + "/" + day + ".csv"
# create file if not existent
if not os.path.isfile(filename):
open(filename, "w+").close()
hnd = open(filename,"a")
a = [str(time()), # timestamp
rargs('s'), # site id
rargs('v'), # version of site
nullwrap(request.remote_addr, # ip address
rargs('u'), # user cookie
rargs('fp'), # user fingerprint
rargs('sr'), # screen resolution
nullwrap(request.headers.get('User-Agent')),
nullwrap(request.headers.get('Referer')),
rargs('e')] # event
for p in a:
hnd.write(p + "\t")
hnd.write("\r\n")
hnd.close()
app.run(host='0.0.0.0')