import sqlite3 import json def create_db(): # Connect to the database (or create it if it doesn't exist) conn = sqlite3.connect('qple_quiz.db') cursor = conn.cursor() # Create the QuizQuestions table # Based on inferred fields: Category, Question, Choices (MultipleChoiceList), Answer, Explanation cursor.execute(''' CREATE TABLE IF NOT EXISTS QuizQuestions ( id INTEGER PRIMARY KEY AUTOINCREMENT, category TEXT, question_text TEXT, choice1 TEXT, choice2 TEXT, choice3 TEXT, choice4 TEXT, correct_answer INTEGER, explanation TEXT, difficulty TEXT, subject TEXT DEFAULT '', passage TEXT, image_url TEXT, correct_answer_str TEXT, raw_json TEXT ) ''') # Sample data reflecting the app's themes (Financial, Job, General Certificate) quiz_data = [ ( '금융(Financial)', '다음 중 유동자산에 해당하지 않는 것은?', '현금', '외상매출금', '단기대여금', '토지', 4, '토지는 비유동자산(유형자산)에 해당합니다.', 'Normal' ), ( '직무(Job)', '프로젝트 관리에서 SWOT 분석의 요소가 아닌 것은?', '강점(Strength)', '기회(Opportunity)', '위협(Threat)', '수익(Profit)', 4, 'SWOT 분석은 강점(Strength), 약점(Weakness), 기회(Opportunity), 위협(Threat)의 약자입니다.', 'Easy' ), ( '자격증(Certificate)', '정보처리기사: OSI 7계층 중 물리적 전송 매체와 관련된 계층은?', '물리 계층', '데이터 링크 계층', '네트워크 계층', '전송 계층', 1, '물리 계층(Physical Layer)은 실제 장치와 전송 매체 간의 물리적인 연결을 담당합니다.', 'Hard' ), ( '금융(Financial)', '주식 시장에서 KOSPI 지수의 기준 시점은?', '1980년 1월 4일', '1990년 1월 4일', '2000년 1월 4일', '1970년 1월 4일', 1, 'KOSPI 지수는 1980년 1월 4일의 시가총액을 100으로 설정하여 계산합니다.', 'Normal' ) ] # Insert sample data cursor.executemany(''' INSERT INTO QuizQuestions (category, question_text, choice1, choice2, choice3, choice4, correct_answer, explanation, difficulty) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ''', quiz_data) # Create a table for App Configuration as well cursor.execute(''' CREATE TABLE IF NOT EXISTS AppConfig ( key TEXT PRIMARY KEY, value TEXT ) ''') config_data = { "serverUrl": "https://qple-api-prod.qpleapp.com/", "googlePacketVersion": "1.5.1", "applePacketVersion": "1.5.1" } for key, value in config_data.items(): cursor.execute('INSERT OR REPLACE INTO AppConfig (key, value) VALUES (?, ?)', (key, value)) # Save (commit) the changes and close the connection conn.commit() conn.close() print("Database 'qple_quiz.db' created and populated successfully.") if __name__ == "__main__": create_db()