summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2023-07-20 21:40:04 -0500
committerMark Powers <mark@marks.kitchen>2023-07-20 21:40:04 -0500
commitdcbeae371f149db313f90df8d1031ace379bdd0c (patch)
tree5d4a7a76282b5bd0a58c10dd96e2964cfeb94d08
parent2e234cc8c81d8d03731b1593135ede18af404b87 (diff)
add post with query string for automationHEADmaster
-rw-r--r--server.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/server.py b/server.py
index d6aeb9a..f2a9173 100644
--- a/server.py
+++ b/server.py
@@ -98,8 +98,11 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
u = urlparse(self.path)
- length = int(self.headers['Content-Length'])
- post_data = json.loads(self.rfile.read(length).decode('utf-8'))
+ try:
+ length = int(self.headers['Content-Length'])
+ post_data = json.loads(self.rfile.read(length).decode('utf-8'))
+ except:
+ post_data = {}
print("POST", u.path)
if u.path == "/submit_payload":
timestamp = datetime.fromtimestamp(int(post_data["timestamp"]/1000))
@@ -155,6 +158,17 @@ class TrackerHTTPRequestHandler(BaseHTTPRequestHandler):
self.send_response(204)
self.end_headers()
self.wfile.write(b"")
+ elif u.path == "/automation":
+ created = datetime.now()
+ q = parse_qs(u.query)
+ if "lat" in q and "lon" in q:
+ with conn.cursor() as cur:
+ cur.execute("INSERT INTO datapoint (datatype, key, value, created) VALUES (%s, %s, %s, %s)", ("geoposition", "latitude", q["lat"], created))
+ cur.execute("INSERT INTO datapoint (datatype, key, value, created) VALUES (%s, %s, %s, %s)", ("geoposition", "longitude", q["lon"], created))
+ conn.commit()
+ self.send_response(204)
+ self.end_headers()
+ self.wfile.write(b"")
else:
self.send_response(404)
self.end_headers()