You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1016 B
Python

#!/usr/bin/env python3
import cgi, os, json, sys
LOG = "radioimplicancies.log"
MAX_ROWS = 3
method = os.environ.get("REQUEST_METHOD", "GET").upper()
if method == "POST":
data = json.load(sys.stdin)
if MAX_ROWS:
rows = []
with open(LOG) as f:
for line in f:
row = json.loads(line)
rows.append(row)
rows = rows[-(MAX_ROWS-1):]
with open(LOG, "w") as f:
for row in rows:
print(json.dumps(row), file=f)
print (json.dumps(data), file=f)
else:
with open(LOG, "a") as f:
print(json.dumps(data), file=f)
print ("Content-type: text/html; charset=utf-8")
print ()
print ("ok")
sys.exit(0)
# debugging
# print ("Content-type: text/html; charset=utf-8")
# print ()
out = []
with open(LOG) as f:
for line in f:
data = json.loads(line)
out.append(data)
print ("Content-type: application/json")
print ()
print (json.dumps(out, indent=2))