plans_ import

This commit is contained in:
hsafaei
2025-11-08 09:08:25 +03:30
parent aa47259860
commit beb23e3feb
3 changed files with 141 additions and 7 deletions
+8 -4
View File
@@ -595,13 +595,17 @@ def extract_codes_to_json( file_excel, tcode_label, file_json):
# ذخیره کد در الاستیک برای شناسه های یافت شده # ذخیره کد در الاستیک برای شناسه های یافت شده
if section_id and section_id != 0: if section_id and section_id != 0:
tcode_mains = [] _source = {}
tcode_subs = [] if code_state :
_source["tcode_mains"] = [tcode_label]
else :
_source["tcode_subs"] = [tcode_label]
data={ data={
'id':section_id, 'id':section_id,
'label': tcode_label, '_source' : _source,
'is_main': int(code_state),
} }
bulk_data.append(data) bulk_data.append(data)
+4 -3
View File
@@ -187,6 +187,7 @@ with open("./data/codes49.json", "r", encoding="utf8") as f:
#------------------------------------- #-------------------------------------
#------ استخراج برخی کدهای باقیمانده که اکسل آنها از قبل موجود هست و تولید فایل مناسب برای درج فایل محور در بانک مجلس #------ استخراج برخی کدهای باقیمانده که اکسل آنها از قبل موجود هست و تولید فایل مناسب برای درج فایل محور در بانک مجلس
#---
#run_codes_extract_directory( "./data/tcodes/corrected_majles/not_edit", "./data/tcodes/corrected_majles/not_edit/result_json", all_codes)
run_codes_extract_directory( "./data/tcodes/corrected_majles/not_edit", "./data/tcodes/corrected_majles/not_edit/result_json", all_codes) #elastic.backupIndexToZipfile("G:/Project2/113", "mj_qa_section", "mj_qa_section_6_codes_no_edit_1")
#-------------------------------------
+129
View File
@@ -0,0 +1,129 @@
import os
import re
import traceback
import json
import time
import pandas as pd
from dotenv import load_dotenv
import sys
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
# from app.common.general_functions import *
from app.common.qanon_functions import *
from app.common.elastic_helper import ElasticHelper
from app.common.config_base import *
def recersive_sections(tcode_label, data, list_bulk, parent_id, child_order , parnet_path=""):
sections = data["subsections"]
for item in sections:
child_sections = []
title = item["title"]
if "subsections" in item :
c_sections = item["subsections"]
child_order += 1
parent_path += item["title"] + '/'
id = uuid.uuid4().hex[:8]
json_ = {
"id" : id,
"title" : title,
"version_key" : "D49_oss120",
"fill_path" : parent_path,
"parent_id": parent_id,
"child_order": child_order,
"tcode": tcode_label,
"time_create": time.time()
}
list_bulk.append(json_)
c_order = 0
recersive_sections(c_sections, list_bulk, parent_id, c_order, parent_path)
def import_paln_json_to_elastic(elastic, file_path, index_name):
try:
# Read JSON file
with open(file_path, 'r', encoding="utf8") as f:
data = json.load(f)
except json.JSONDecodeError as e:
raise ValueError(f"Failed to parse JSON file: {str(e)}")
except FileNotFoundError:
raise FileNotFoundError(f"File not found: {file_path}")
list_bulk = []
batch_size = 200
processed_count = 0
total_update = 0
tcode_label = ""
if "law_title" in data :
tcode_label = data["tcode_label"]
if not tcode_label :
print(" error tcode_label", file_path)
return
parent_id = 0
child_order = 0
# tree_order = 0
sections = data["sections"]
parent_path = ""
for item in sections:
child_sections = []
if "subsections" in item :
c_sections = item["subsections"]
c_order = 0
parent_path += item["title"] + '/'
recersive_sections(tcode_label, c_sections, list_bulk, parent_id, c_order, parent_path)
if len(list_bulk) >= batch_size :
elastic.updateBulkList(list_bulk, index_name_o)
total_update += len(list_bulk)
list_bulk = []
print("updated batch : ", batch_size_number, f" {total_update}/{total} --->", file_path)
batch_size_number += 1
if list_bulk:
elastic.updateBulkList(list_bulk, index_name_o)
total_update += len(list_bulk)
print(" .... finish updated batch : ", batch_size_number, f" {total_update}/{total} --->", file_path)
batch_size_number += 1
# -------------------------------------------------------------------- Run
if __name__ == "__main__":
load_dotenv(dotenv_path='config.env')
host=os.getenv('HOST_160')
password=os.getenv('HOST_160_PASS')
# host=os.getenv('HOST_112')
# password=os.getenv('HOST_112_PASS')
# host=os.getenv('HOST_113')
# password=os.getenv('HOST_113_PASS')
print('.... codes_import_from_excel ......', host)
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
elastic = ElasticHelper(host, password, "elastic", path_base_map)
# all_codes = []
# with open("./data/codes49.json", "r", encoding="utf8") as f:
# codes_1 = json.load(f)
# all_codes = codes_1