lvl2.1
This commit is contained in:
+24
-12
@@ -1,24 +1,29 @@
|
||||
# --------------------------- modularity
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
from pydantic import BaseModel
|
||||
from base_model import MnTerm
|
||||
|
||||
# --------------------------- global-params
|
||||
input_es_index_name = ''
|
||||
base_index_name = 'monir_test_term'
|
||||
id_data = None
|
||||
_data = None
|
||||
|
||||
|
||||
# --------------------------- function
|
||||
def generate_pydantic_model_from_mapping(model_name: str, mapping_es: dict) -> type[BaseModel]:
|
||||
fields = {}
|
||||
for field_name, field_def in mapping["properties"].items():
|
||||
es_type = field_def["type"]
|
||||
py_type = ES_TO_PYDANTIC.get(es_type, str)
|
||||
|
||||
# اضافه کردن optional بودن؟ یا default؟ بسته به نیاز
|
||||
fields[field_name] = (py_type, ...)
|
||||
|
||||
return type(name, (BaseModel,), {"__annotations__": fields})
|
||||
def conver_mn_term(old_data) -> MnTerm:
|
||||
new_data = {
|
||||
id: str
|
||||
main_type: str
|
||||
sub_type: str
|
||||
title: str
|
||||
content: str
|
||||
author: str
|
||||
begin_date: datetime
|
||||
end_date: datetime
|
||||
begin_year: int
|
||||
tags: str
|
||||
keywords: str
|
||||
}
|
||||
|
||||
|
||||
# --------------------------- flow
|
||||
@@ -35,4 +40,11 @@ es_helper.update_index_doc(
|
||||
index_name_o=base_index_name,
|
||||
eid=id_data,
|
||||
data=_data
|
||||
)
|
||||
)
|
||||
|
||||
# --------------------------- RUN
|
||||
# ------ command
|
||||
# --liunx
|
||||
# python3 -m app.monir.sanad_stuff.py
|
||||
# --windows
|
||||
# python -m app.monir.sanad_stuff.py
|
||||
|
||||
Reference in New Issue
Block a user