radioimplicancies.cgi

master
Michael Murtaugh 5 years ago
parent b97369446d
commit 45dd322c27

@ -0,0 +1,45 @@
#!/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))
Loading…
Cancel
Save