fix: Lade Lektionen korrekt aus JSON-Datei oder verwende Fallback-Lektionen

Co-authored-by: aider (ollama_chat/qwen3-coder:30b) <aider@aider.chat>
This commit is contained in:
jamulix 2025-10-21 15:09:05 +02:00
commit 8a8c469742

42
app.py
View file

@ -20,32 +20,32 @@ FALLBACK_LESSONS = [
DATA_PATH = os.path.join(app.root_path, "data", "lessons.json")
lessons = []
try:
if os.path.exists(DATA_PATH):
with open(DATA_PATH, "r", encoding="utf-8") as f:
lessons = json.load(f)
print(f"Erfolgreich {len(lessons)} Lektionen aus {DATA_PATH} geladen")
else:
print(f"Warnung: Datei {DATA_PATH} nicht gefunden. Verwende Fallback-Lektionen.")
def load_lessons():
"""Lädt Lektionen aus der JSON-Datei oder verwendet Fallback"""
global lessons
try:
if os.path.exists(DATA_PATH):
with open(DATA_PATH, "r", encoding="utf-8") as f:
lessons = json.load(f)
print(f"Erfolgreich {len(lessons)} Lektionen aus {DATA_PATH} geladen")
else:
print(f"Warnung: Datei {DATA_PATH} nicht gefunden. Verwende Fallback-Lektionen.")
lessons = FALLBACK_LESSONS
except json.JSONDecodeError as e:
print(f"Fehler beim Laden der JSON-Datei: {e}")
print("Verwende Fallback-Lektionen")
lessons = FALLBACK_LESSONS
except Exception as e:
print(f"Unerwarteter Fehler beim Laden der Lektionen: {e}")
print("Verwende Fallback-Lektionen")
lessons = FALLBACK_LESSONS
except json.JSONDecodeError as e:
print(f"Fehler beim Laden der JSON-Datei: {e}")
print("Verwende Fallback-Lektionen")
lessons = FALLBACK_LESSONS
except Exception as e:
print(f"Unerwarteter Fehler beim Laden der Lektionen: {e}")
print("Verwende Fallback-Lektionen")
lessons = FALLBACK_LESSONS
# Sicherstellen, dass Lektionen vorhanden sind
if not lessons:
print("Keine Lektionen verfügbar, verwende Fallback-Lektionen")
lessons = FALLBACK_LESSONS
# Datenbanktabellen erstellen
# Datenbanktabellen erstellen und Lektionen laden
with app.app_context():
db.create_all()
print("Datenbanktabellen wurden initialisiert")
load_lessons()
print(f"{len(lessons)} Lektionen geladen")
@app.route('/')
def index():