import json import logging from typing import List, Tuple from .db_manager import DatabaseManager logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) def adicionar_lote_questoes(db: DatabaseManager, questoes: list) -> Tuple[bool, str]: """Adiciona várias questões de uma vez""" try: conn = db.get_connection() cursor = conn.cursor() for questao in questoes: cursor.execute(''' INSERT INTO previous_questions (year, area, question_text, options, correct_answer, explanation, difficulty, ref_sources, tags) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) ''', ( questao.get('year'), questao.get('area'), questao.get('question_text'), json.dumps(questao.get('options', {})), questao.get('correct_answer'), questao.get('explanation'), questao.get('difficulty', 'medium'), json.dumps(questao.get('references', [])), json.dumps(questao.get('tags', [])) )) conn.commit() logger.info(f"Adicionadas {len(questoes)} questões com sucesso") return True, "Questões adicionadas com sucesso" except Exception as e: logger.error(f"Erro ao adicionar questões: {e}") return False, f"Erro ao adicionar questões: {str(e)}"