diff options
author | Mark Powers <mark@marks.kitchen> | 2023-07-20 21:40:04 -0500 |
---|---|---|
committer | Mark Powers <mark@marks.kitchen> | 2023-07-20 21:40:04 -0500 |
commit | dcbeae371f149db313f90df8d1031ace379bdd0c (patch) | |
tree | 5d4a7a76282b5bd0a58c10dd96e2964cfeb94d08 | |
parent | 2e234cc8c81d8d03731b1593135ede18af404b87 (diff) |
-rw-r--r-- | server.py | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -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() |