mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-04 04:14:58 +00:00
changed db connection
This commit is contained in:
@@ -108,15 +108,6 @@ def move():
|
||||
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'])
|
||||
def data():
|
||||
@@ -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)
|
||||
# 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()
|
||||
# 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:
|
||||
|
Reference in New Issue
Block a user