cgi shenanigans
This commit is contained in:
parent
380505695e
commit
6a7fe86063
4 changed files with 79 additions and 1982 deletions
39
userdb/db.py
Normal file
39
userdb/db.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import json
|
||||
import os
|
||||
from flask import Flask, request
|
||||
from functools import reduce
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/track", methods = ['GET'])
|
||||
def track():
|
||||
if request.method == 'GET' and request.args.get('hash'):
|
||||
hash = str(request.args.get('hash'))
|
||||
ua = str(request.args.get('ua'))
|
||||
url = str(request.values.get("url") or request.headers.get("Referer"))
|
||||
if os.path.exists('db.json'):
|
||||
with open('db.json', 'r') as db:
|
||||
db = json.loads(db.read())
|
||||
else:
|
||||
db = {}
|
||||
if hash in db.keys():
|
||||
visits = db[hash]['visits']
|
||||
else:
|
||||
visits = list()
|
||||
|
||||
visits.append(url)
|
||||
visits = list(set(visits))
|
||||
db.update({
|
||||
hash : {
|
||||
'visits' : visits,
|
||||
'agent' : ua
|
||||
}
|
||||
})
|
||||
with open('db.json', 'w+') as dbw:
|
||||
dbw.write(json.dumps(db, indent=4))
|
||||
|
||||
return str(len(db[hash]))
|
||||
else:
|
||||
return 'hash missing'
|
||||
|
||||
app.run()
|
||||
Loading…
Add table
Add a link
Reference in a new issue