From ebd88e43abcb4bb6aa7013cae7d7198cab836269 Mon Sep 17 00:00:00 2001 From: "ishak jmilou.ishak" Date: Tue, 14 Jan 2025 13:23:48 +0100 Subject: [PATCH] Add error handling and database insertion for YOLO results --- src/Python/flask/web/app.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index d6e908c..549964e 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -163,6 +163,18 @@ def yolo_results_endpoint(): global yolo_results with lock: return jsonify(yolo_results) + try: + data = json.loads(yolo_results) + db = get_db() + with db.cursor() as cursor: + sql_yolo = "INSERT INTO image (class, confidence) VALUES (%s, %s)" + cursor.executemany(sql_yolo, data) + db.commit() + cursor.close() + except json.JSONDecodeError as e: + print(f"JSON decode error: {e}") + except mysql.connector.Error as err: + print(f"Database error: {err}") if __name__ == '__main__':