modules.db.py integrity
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
import sqlite3
|
||||
import os
|
||||
from datetime import datetime, timedelta
|
||||
from modules.socketio import resend_static_data
|
||||
import random
|
||||
|
||||
DB_PATH = os.path.join(os.path.dirname(__file__), '../db/commands.db')
|
||||
DB_PATH_COFFEE = os.path.join(os.path.dirname(__file__), '../db/coffee.db')
|
||||
|
||||
### THIS CODE IS NOT PROOFED BUT LOOKS RIGHT###
|
||||
|
||||
def update_command_status(command_id, status):
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
@@ -20,7 +22,6 @@ def update_command_status(command_id, status):
|
||||
conn.close()
|
||||
print(f"[DB] Befehl {command_id} auf {status} aktualisiert.")
|
||||
return status
|
||||
### THIS CODE IS NOT PROOFED BUT LOOKS RIGHT###
|
||||
|
||||
def get_coffee_count():
|
||||
conn = sqlite3.connect(DB_PATH_COFFEE)
|
||||
@@ -40,4 +41,45 @@ def get_coffees():
|
||||
coffees = cursor.fetchall()
|
||||
|
||||
conn.close()
|
||||
return coffees
|
||||
return coffees
|
||||
def create_toggle_machine():
|
||||
randID = random.randint(1000, 9999)
|
||||
fullCommand = {'command': 'toggle_machine', 'status': 'pending', 'command_id': randID}
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
INSERT INTO commands (command, status, command_id)
|
||||
VALUES (?, ?, ?)
|
||||
""", (fullCommand["command"], fullCommand["status"], fullCommand["command_id"]))
|
||||
|
||||
resend_static_data()
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return fullCommand
|
||||
|
||||
def create_make_coffee():
|
||||
randID = random.randint(1000, 9999)
|
||||
fullCommand = {'command': 'make_coffee', 'status': 'pending', 'command_id': randID}
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute("""
|
||||
INSERT INTO commands (command, status, command_id)
|
||||
VALUES (?, ?, ?)
|
||||
""", (fullCommand["command"], fullCommand["status"], fullCommand["command_id"]))
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return fullCommand
|
||||
|
||||
def create_coffee_entry():
|
||||
conn = sqlite3.connect(DB_PATH_COFFEE)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
INSERT INTO coffee (user, status)
|
||||
VALUES (?, ?)
|
||||
""", ("admin", "served"))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
from modules.persistence import load_dict, save_dict
|
||||
from modules.socketio import resend_static_data
|
||||
from modules.db import create_coffee_entry
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
@@ -30,15 +31,18 @@ def track_coffee_made(data, flanksUp, flanksDown):
|
||||
#logic for tracking coffee made
|
||||
|
||||
if coffee_made:
|
||||
conn = sqlite3.connect(DB_PATH_COFFEE)
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
INSERT INTO coffee (user, status)
|
||||
VALUES (?, ?)
|
||||
""", ("admin", "served"))
|
||||
conn.commit()
|
||||
conn.close()
|
||||
create_coffee_entry()
|
||||
#change to insert coffee at modules.db
|
||||
# conn = sqlite3.connect(DB_PATH_COFFEE)
|
||||
# cursor = conn.cursor()
|
||||
# cursor.execute("""
|
||||
# INSERT INTO coffee (user, status)
|
||||
# VALUES (?, ?)
|
||||
# """, ("admin", "served"))
|
||||
# conn.commit()
|
||||
# conn.close()
|
||||
print("Coffee made detected, data saved.")
|
||||
# update water fill and beans fill and coffeeOn water and beans
|
||||
return
|
||||
|
||||
def track_error_water(data, flanksUp, flanksDown):
|
||||
|
||||
Reference in New Issue
Block a user