From 85345ca45ffb7c96d90353f3ff529faf561b7586 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Tue, 28 Oct 2025 17:21:10 -0700 Subject: [PATCH] Update db_admin.py --- etc/db_admin.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 68 insertions(+), 2 deletions(-) diff --git a/etc/db_admin.py b/etc/db_admin.py index eb7d855..f494bf9 100644 --- a/etc/db_admin.py +++ b/etc/db_admin.py @@ -1,5 +1,8 @@ # Load the bbs messages from the database file to screen for admin functions -import pickle # pip install pickle +import pickle +import sqlite3 + +print ("\n Meshing-Around Database Admin Tool\n") # load the bbs messages from the database file @@ -106,7 +109,70 @@ except Exception as e: golfsim_score = "System: data/golfsim_hs.pkl not found" -print ("\n Meshing-Around Database Admin Tool\n") +# checklist.db admin display +print("\nCurrent Check-ins Table\n") + +try: + conn = sqlite3.connect('../data/checklist.db') +except Exception: + conn = sqlite3.connect('data/checklist.db') +c = conn.cursor() +try: + c.execute(""" + SELECT * FROM checkin + WHERE removed = 0 + ORDER BY checkin_id DESC + LIMIT 20 + """) + rows = c.fetchall() + col_names = [desc[0] for desc in c.description] + if rows: + # Print header + header = " | ".join(f"{name:<15}" for name in col_names) + print(header) + print("-" * len(header)) + # Print rows + for row in rows: + print(" | ".join(f"{str(col):<15}" for col in row)) + else: + print("No check-ins found.") +except Exception as e: + print(f"Error reading check-ins: {e}") +finally: + conn.close() + +# inventory.db admin display +print("\nCurrent Inventory Table\n") +try: + conn = sqlite3.connect('../data/inventory.db') +except Exception: + conn = sqlite3.connect('data/inventory.db') +c = conn.cursor() +try: + c.execute(""" + SELECT * FROM inventory + ORDER BY item_id DESC + LIMIT 20 + """) + rows = c.fetchall() + col_names = [desc[0] for desc in c.description] + if rows: + # Print header + header = " | ".join(f"{name:<15}" for name in col_names) + print(header) + print("-" * len(header)) + # Print rows + for row in rows: + print(" | ".join(f"{str(col):<15}" for col in row)) + else: + print("No inventory items found.") +except Exception as e: + print(f"Error reading inventory: {e}") +finally: + conn.close() + + +# Pickle database displays print ("System: bbs_messages") print (bbs_messages) print ("\nSystem: bbs_dm")