From 6767491e019f4a5c04f87779d213fcc1f5b272d2 Mon Sep 17 00:00:00 2001 From: TILL TOMCZAK Date: Fri, 17 May 2024 14:25:00 +0200 Subject: [PATCH] Create datenbank_erstellen.py --- api-backend_blueprint/datenbank_erstellen.py | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 api-backend_blueprint/datenbank_erstellen.py diff --git a/api-backend_blueprint/datenbank_erstellen.py b/api-backend_blueprint/datenbank_erstellen.py new file mode 100644 index 0000000..efa3eac --- /dev/null +++ b/api-backend_blueprint/datenbank_erstellen.py @@ -0,0 +1,25 @@ +import sqlite3 +from dotenv import load_dotenv +import os + +load_dotenv() +printers = os.getenv('PRINTER_IPS').split(',') + +def create_db(): + conn = sqlite3.connect('printers.db') + c = conn.cursor() + + # Tabelle 'printers' erstellen, falls sie nicht existiert + c.execute('''CREATE TABLE IF NOT EXISTS printers + (ip TEXT PRIMARY KEY, status TEXT)''') + + # Drucker-IPs in die Tabelle einfügen, falls sie noch nicht vorhanden sind + for printer_ip in printers: + c.execute("INSERT OR IGNORE INTO printers (ip, status) VALUES (?, ?)", (printer_ip, "frei")) + + conn.commit() + conn.close() + print("Datenbank 'printers.db' erfolgreich erstellt.") + +if __name__ == '__main__': + create_db()