From 8dbffe2e63c882ab79610e89b474a3390944126a Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sat, 18 Jan 2025 14:01:14 -0800 Subject: [PATCH] enhance --- modules/checklist.py | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/modules/checklist.py b/modules/checklist.py index 96efde9..dfeafb0 100644 --- a/modules/checklist.py +++ b/modules/checklist.py @@ -3,6 +3,7 @@ import sqlite3 from modules.log import * +import time trap_list_checklist = ("checkin", "checkout", "checklist", "purgein", "purgeout") @@ -24,10 +25,17 @@ def checkin(name, date, time, notes): # checkin a user conn = sqlite3.connect(checklist_db) c = conn.cursor() - c.execute("INSERT INTO checkin (checkin_name, checkin_date, checkin_time, checkin_notes) VALUES (?, ?, ?, ?)", (name, date, time, notes)) + try: + c.execute("INSERT INTO checkin (checkin_name, checkin_date, checkin_time, checkin_notes) VALUES (?, ?, ?, ?)", (name, date, time, notes)) + except sqlite3.OperationalError as e: + if "no such table" in str(e): + initialize_checklist_database() + c.execute("INSERT INTO checkin (checkin_name, checkin_date, checkin_time, checkin_notes) VALUES (?, ?, ?, ?)", (name, date, time, notes)) + else: + raise conn.commit() conn.close() - return "Checked in: " + name + return "Checked in: " def delete_checkin(checkin_id): # delete a checkin @@ -42,10 +50,17 @@ def checkout(name, date, time, notes): # checkout a user conn = sqlite3.connect(checklist_db) c = conn.cursor() - c.execute("INSERT INTO checkout (checkout_name, checkout_date, checkout_time, checkout_notes) VALUES (?, ?, ?, ?)", (name, date, time, notes)) + try: + c.execute("INSERT INTO checkout (checkout_name, checkout_date, checkout_time, checkout_notes) VALUES (?, ?, ?, ?)", (name, date, time, notes)) + except sqlite3.OperationalError as e: + if "no such table" in str(e): + initialize_checklist_database() + c.execute("INSERT INTO checkout (checkout_name, checkout_date, checkout_time, checkout_notes) VALUES (?, ?, ?, ?)", (name, date, time, notes)) + else: + raise conn.commit() conn.close() - return "Checked out: " + name + return "Checked out: " def delete_checkout(checkout_id): # delete a checkout @@ -75,18 +90,18 @@ def list_checkin(): return checkin_list def handle_checklist(nodeID, message): - date = datetime.datetime.now().strftime("%Y-%m-%d") - time = datetime.datetime.now().strftime("%H:%M:%S") + current_date = time.strftime("%Y-%m-%d") + current_time = time.strftime("%H:%M:%S") # handle checklist commands - if message[0].lower() == "checkin": - return checkin(nodeID, date, time, message[1]) - elif message[0].lower() == "checkout": - return checkout(nodeID, date, time, message[1]) - elif message[0].lower() == "purgein": + if "checkin" in message.lower(): + return checkin(nodeID, current_date, current_time, message[1]) + elif "checkout" in message.lower(): + return checkout(nodeID, current_date, current_time, message[1]) + elif "purgein" in message.lower(): return delete_checkin(nodeID) - elif message[0].lower() == "purgeout": + elif "purgeout" in message.lower(): return delete_checkout(nodeID) - elif message[0].lower() == "checklist": + elif "checklist" in message.lower(): return list_checkin() else: return "Invalid command." \ No newline at end of file