first commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import sys
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
from app.common.data_helper import DataHelper
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
load_dotenv(dotenv_path=r"D:\init_mahdi\dataParsers\config.env")
|
||||
|
||||
|
||||
host = os.getenv("HOST_99")
|
||||
password = os.getenv("PASSWORD_99")
|
||||
|
||||
print(f"host {host} password {password}")
|
||||
elastic = ElasticHelper(es_url=host, es_pass=password, es_user="elastic")
|
||||
|
||||
|
||||
def create_data(
|
||||
_index_name: str,
|
||||
input_path: Path,
|
||||
bulk_size=200,
|
||||
):
|
||||
|
||||
f_data = []
|
||||
f_counter = 0
|
||||
# input_data = DataHelper.load_orjson(
|
||||
# # r"D:\init_mahdi\dataParsers\data\index_image_11k.json"
|
||||
# r"D:\init_mahdi\dataParsers\data\monir_mn_voice_sanad.json"
|
||||
# )
|
||||
for data_path in Path(input_path).rglob("*.json"):
|
||||
input_data = DataHelper.load_orjson(data_path)
|
||||
for data in input_data:
|
||||
f_data.append({"_id": data["_id"], "_source": data["_source"]})
|
||||
|
||||
if len(f_data) >= bulk_size:
|
||||
f_counter += len(f_data)
|
||||
elastic.importBulkList(listData=f_data, index_name=_index_name)
|
||||
print(f"---- {f_counter}/{len(input_data)} ----")
|
||||
f_data = []
|
||||
|
||||
if len(f_data) > 0:
|
||||
f_counter += len(f_data)
|
||||
elastic.importBulkList(listData=f_data, index_name=_index_name)
|
||||
print(f"---- {f_counter}/{len(input_data)} ----")
|
||||
f_data = []
|
||||
|
||||
print(":D")
|
||||
|
||||
|
||||
create_data(
|
||||
# _index_name="monir_ocr_lib",
|
||||
# _index_name="monir_mn_voice_sanad",
|
||||
_index_name="majles_group_mashruh",
|
||||
input_path=Path(r"D:\init_mahdi\dataParsers\data\index_mashruh_group"),
|
||||
)
|
||||
|
||||
# source $HOME/.dataParsers/bin/activate
|
||||
# cd /home/sabr/dataParsers
|
||||
# python3 -m app.put_data_ocr
|
||||
# python -m app.put_data_ocr
|
||||
Reference in New Issue
Block a user