Create datenbank_erstellen.py
This commit is contained in:
parent
4793bdaf71
commit
6767491e01
25
api-backend_blueprint/datenbank_erstellen.py
Normal file
25
api-backend_blueprint/datenbank_erstellen.py
Normal file
@ -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()
|
Loading…
x
Reference in New Issue
Block a user