Spaces:
Runtime error
Runtime error
danielraynaud
commited on
Update database/db_operations.py
Browse files
database/db_operations.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# database/db_operations.py
|
2 |
-
|
3 |
import json
|
4 |
import logging
|
5 |
from typing import List, Tuple
|
@@ -8,7 +6,8 @@ from .db_manager import DatabaseManager
|
|
8 |
logging.basicConfig(level=logging.INFO)
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
11 |
-
def adicionar_lote_questoes(db: DatabaseManager, questoes: list):
|
|
|
12 |
try:
|
13 |
conn = db.get_connection()
|
14 |
cursor = conn.cursor()
|
@@ -17,7 +16,7 @@ def adicionar_lote_questoes(db: DatabaseManager, questoes: list):
|
|
17 |
cursor.execute('''
|
18 |
INSERT INTO previous_questions
|
19 |
(year, area, question_text, options, correct_answer,
|
20 |
-
explanation, difficulty, ref_sources, tags)
|
21 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
22 |
''', (
|
23 |
questao.get('year'),
|
@@ -27,11 +26,13 @@ def adicionar_lote_questoes(db: DatabaseManager, questoes: list):
|
|
27 |
questao.get('correct_answer'),
|
28 |
questao.get('explanation'),
|
29 |
questao.get('difficulty', 'medium'),
|
30 |
-
json.dumps(questao.get('references', [])),
|
31 |
json.dumps(questao.get('tags', []))
|
32 |
))
|
33 |
|
34 |
conn.commit()
|
|
|
35 |
return True, "Questões adicionadas com sucesso"
|
36 |
except Exception as e:
|
|
|
37 |
return False, f"Erro ao adicionar questões: {str(e)}"
|
|
|
|
|
|
|
1 |
import json
|
2 |
import logging
|
3 |
from typing import List, Tuple
|
|
|
6 |
logging.basicConfig(level=logging.INFO)
|
7 |
logger = logging.getLogger(__name__)
|
8 |
|
9 |
+
def adicionar_lote_questoes(db: DatabaseManager, questoes: list) -> Tuple[bool, str]:
|
10 |
+
"""Adiciona várias questões de uma vez"""
|
11 |
try:
|
12 |
conn = db.get_connection()
|
13 |
cursor = conn.cursor()
|
|
|
16 |
cursor.execute('''
|
17 |
INSERT INTO previous_questions
|
18 |
(year, area, question_text, options, correct_answer,
|
19 |
+
explanation, difficulty, ref_sources, tags)
|
20 |
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
21 |
''', (
|
22 |
questao.get('year'),
|
|
|
26 |
questao.get('correct_answer'),
|
27 |
questao.get('explanation'),
|
28 |
questao.get('difficulty', 'medium'),
|
29 |
+
json.dumps(questao.get('references', [])),
|
30 |
json.dumps(questao.get('tags', []))
|
31 |
))
|
32 |
|
33 |
conn.commit()
|
34 |
+
logger.info(f"Adicionadas {len(questoes)} questões com sucesso")
|
35 |
return True, "Questões adicionadas com sucesso"
|
36 |
except Exception as e:
|
37 |
+
logger.error(f"Erro ao adicionar questões: {e}")
|
38 |
return False, f"Erro ao adicionar questões: {str(e)}"
|