diff options
-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() |