malo čiščenja kode in robustnostni popravek (kreiranje prazne sheme)
This commit is contained in:
15
db_schema.py
Normal file
15
db_schema.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import sqlite3
|
||||
|
||||
def create_tables(conn):
|
||||
"""
|
||||
Ustvari potrebne tabele v bazi, če še ne obstajajo.
|
||||
"""
|
||||
cursor = conn.cursor()
|
||||
cursor.execute('''
|
||||
CREATE TABLE IF NOT EXISTS songs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
title TEXT,
|
||||
lyrics TEXT
|
||||
)
|
||||
''')
|
||||
conn.commit()
|
||||
@@ -31,6 +31,7 @@ import tkinter.messagebox as messagebox
|
||||
from web.server import start_server_thread
|
||||
import urllib.request
|
||||
import tempfile
|
||||
from db_schema import create_tables
|
||||
|
||||
DB_PATH = 'songs.db'
|
||||
SETTINGS_PATH = 'settings.json'
|
||||
@@ -46,6 +47,7 @@ class SongProjector:
|
||||
# Odpri read-only; ne bo ustvaril prazne baze, če datoteka manjka
|
||||
# check_same_thread=False omogoča uporabo v večih nitih
|
||||
self.conn = sqlite3.connect(DB_PATH, check_same_thread=False)
|
||||
create_tables(self.conn)
|
||||
self.cursor = self.conn.cursor()
|
||||
except sqlite3.OperationalError as e:
|
||||
# Jasno sporočilo in varen izhod
|
||||
|
||||
@@ -5,6 +5,11 @@ import sqlite3
|
||||
import json
|
||||
import os
|
||||
import urllib.request
|
||||
import sys
|
||||
|
||||
# Dodajanje poti do korenskega imenika, da lahko uvozimo db_schema
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from db_schema import create_tables
|
||||
|
||||
DB_PATH = 'songs.db'
|
||||
SETTINGS_PATH = 'settings.json'
|
||||
@@ -15,22 +20,16 @@ EXPORT_PATH = 'pesmi_export.txt'
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
if not os.path.exists(SETTINGS_PATH):
|
||||
print("Nastavitve manjkajo! Zaženi 'nastavitve.bat' najprej.")
|
||||
print("Nastavitve manjkajo! Zaženi program za prjekcijo, da jih pripravi.")
|
||||
exit()
|
||||
|
||||
with open(SETTINGS_PATH, "r", encoding="utf-8") as f:
|
||||
settings = json.load(f)
|
||||
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
create_tables(conn)
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('''CREATE TABLE IF NOT EXISTS songs (
|
||||
id INTEGER PRIMARY KEY,
|
||||
title TEXT,
|
||||
lyrics TEXT
|
||||
)''')
|
||||
conn.commit()
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# POMOŽNE FUNKCIJE
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user