diff --git a/src/Python/flask/web/app.py b/src/Python/flask/web/app.py index ed6603d..d6e908c 100644 --- a/src/Python/flask/web/app.py +++ b/src/Python/flask/web/app.py @@ -107,15 +107,6 @@ def move(): cursor.close() db_connection.close() return jsonify({"status": "success", "direction": direction}) - -@app.route("/database") -def database(): - db = get_db() - cursor = db.cursor() - cursor.execute("SELECT * FROM kobuki_data") - rows = cursor.fetchall() - cursor.close() - return str(rows) @app.route('/data', methods=['GET']) @@ -139,15 +130,15 @@ def data(): # Database-insert db = get_db() - cursor = db.cursor() + with db.cursor() as cursor: - # Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value` - sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)" - cursor.executemany(sql_sensor, sensor_data_tuples) - - # Commit en sluit de cursor - db.commit() - cursor.close() + # Zorg dat je tabel `kobuki_data` kolommen heeft: `name` en `value` + sql_sensor = "INSERT INTO kobuki_data (name, value) VALUES (%s, %s)" + cursor.executemany(sql_sensor, sensor_data_tuples) + + # Commit en sluit de cursor + db.commit() + cursor.close() except json.JSONDecodeError as e: print(f"JSON decode error: {e}") except mysql.connector.Error as err: