diff options
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/load_quiz_data.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/scripts/load_quiz_data.py b/scripts/load_quiz_data.py index 6b0a6c9..25186e6 100644 --- a/scripts/load_quiz_data.py +++ b/scripts/load_quiz_data.py @@ -25,11 +25,23 @@ def load_questions(json_path, db_path): # Insert questions for q in questions: + # Handle null options and different JSON structure + options = [str(o).strip() if o else "" for o in q['options']] + while len(options) < 4: # Ensure we always have 4 options + options.append("") + c.execute('''INSERT INTO questions (id, text, option1, option2, option3, option4, correct_index, requirement, explanation) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)''', - (q['id'], q['text'], q['option1'], q['option2'], q['option3'], q['option4'], - q['correct_index'], q.get('requirement', ''), q.get('explanation', ''))) + (q['id'], + q['question'], + options[0], + options[1], + options[2], + options[3], + q['correct_index'], + q.get('requirement', ''), + q.get('explanation', ''))) conn.commit() conn.close() |