Feature: 40 bilingual questions, random 10 game run, difficulty levels, and full i18n support

This commit is contained in:
kobold-ai
2026-09-21 12:33:34 +02:00
parent eafa1f833e
commit cf89cd31c7
15 changed files with 1369 additions and 138 deletions
+6 -46
View File
@@ -3,6 +3,7 @@ import json
from app.database import engine, SessionLocal, Base
from app.models import Question, AdminUser
from app.auth import hash_password
from app.seed_40 import seed_40_questions
def seed_db():
Base.metadata.create_all(bind=engine)
@@ -22,52 +23,11 @@ def seed_db():
db.commit()
print(f"Created default admin user: {admin_user}")
# 2. Existing Questions from legacy/fragen.json
legacy_questions_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "legacy", "fragen.json")
if os.path.exists(legacy_questions_path):
with open(legacy_questions_path, "r", encoding="utf-8") as f:
legacy_questions = json.load(f)
count = 0
for idx, q in enumerate(legacy_questions):
# Check if question text already in DB
existing = db.query(Question).filter(Question.question == q.get("frage", "").strip()).first()
if not existing:
db.add(Question(
category="harry_potter",
question=q.get("frage", "").strip(),
canonical_answer=q.get("antwort", "").strip(),
hint=q.get("tipp", "").strip(),
status="active",
sort_order=idx + 1,
submitted_by="Admin"
))
count += 1
db.commit()
print(f"Imported {count} active questions from legacy/fragen.json")
# 3. Existing Suggestions from legacy/fragen_vorschlaege.json
legacy_sugg_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "legacy", "fragen_vorschlaege.json")
if os.path.exists(legacy_sugg_path):
with open(legacy_sugg_path, "r", encoding="utf-8") as f:
legacy_sugg = json.load(f)
count_sugg = 0
for q in legacy_sugg:
existing = db.query(Question).filter(Question.question == q.get("frage", "").strip()).first()
if not existing:
db.add(Question(
category="harry_potter",
question=q.get("frage", "").strip(),
canonical_answer=q.get("antwort", "").strip(),
hint=q.get("tipp", "").strip(),
status="needs_review",
sort_order=999,
submitted_by="Gast (Legacy Vorschlag)"
))
count_sugg += 1
db.commit()
print(f"Imported {count_sugg} pending suggestions from legacy/fragen_vorschlaege.json")
# 2. Seed 40 questions if database is empty
question_count = db.query(Question).count()
if question_count == 0:
print("Question table is empty, seeding 40 initial bilingual questions...")
seed_40_questions()
finally:
db.close()