4
from fastapi_restful.tasks import repeat_every
5
from pydantic import BaseModel
6
from pydantic.v1.schema import schema
8
from app.front.tkq import broker
10
logging.basicConfig(level=logging.INFO)
11
logger = logging.getLogger(__name__)
16
async def import_prepare_data(model: str, data: list, ):
19
import_schema: BaseModel
20
header = list(data[0].keys())
25
import_schema = model.schemas.update
28
import_schema = model.schemas.create
29
for i, line in enumerate(data):
31
line = import_schema(**line)
32
except Exception as ex:
33
logger.error(f'Error in line {i}: {ex}')
34
for er in ex.errors():
37
'type': er.get('type'),
38
'msg': f"{er.get('msg')}: Input value: {er.get('input')}",
39
'field': str(er.get('loc')[0])
42
lines.append(line.model_dump(mode='json'))
43
return errors, lines, mode
46
async def import_save(model: str, data: list):
49
import_schema: BaseModel
50
imported_lines: list = []
51
async with model.adapter as a:
53
resp = await a.create(json=line, model=model.name)
54
imported_lines.append(resp)