import majles...
This commit is contained in:
@@ -3,6 +3,7 @@ import re
|
||||
import traceback
|
||||
import json
|
||||
import pandas as pd
|
||||
import copy
|
||||
from dotenv import load_dotenv
|
||||
|
||||
import sys
|
||||
@@ -590,7 +591,7 @@ def importCodesToElastic(elastic, file_excel, index_name_o, tcode_label, file_lo
|
||||
|
||||
file.close()
|
||||
|
||||
def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_top=False):
|
||||
def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_top=False, with_history_code={}):
|
||||
|
||||
|
||||
if head_top :
|
||||
@@ -646,21 +647,34 @@ def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_t
|
||||
|
||||
|
||||
data={}
|
||||
# ذخیره کد در الاستیک برای شناسه های یافت شده
|
||||
# ذخیره کد برای شناسه های یافت شده
|
||||
if section_id and section_id != 0:
|
||||
|
||||
_source = {}
|
||||
history_codes= []
|
||||
sub_key = ''
|
||||
if code_state :
|
||||
_source["tcode_mains"] = [tcode_label]
|
||||
sub_key = 'main'
|
||||
else :
|
||||
_source["tcode_subs"] = [tcode_label]
|
||||
|
||||
sub_key = 'sub'
|
||||
|
||||
if with_history_code :
|
||||
hc = copy.deepcopy(with_history_code)
|
||||
hc["sub_key"]= sub_key
|
||||
history_codes.append(hc)
|
||||
_source["history_codes"] = history_codes
|
||||
|
||||
# if section_id == 'qs2549941' :
|
||||
# print(section_id)
|
||||
|
||||
data={
|
||||
'id':section_id,
|
||||
'_source' : _source,
|
||||
'_source' : _source
|
||||
}
|
||||
|
||||
|
||||
bulk_data.append(data)
|
||||
|
||||
with open(file_json, "w", encoding="utf8") as f:
|
||||
@@ -670,7 +684,8 @@ def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_t
|
||||
print('######################## Exception error --- row_number : ' , str(row_number), '/', str(count) , ' ***' , str(e) )
|
||||
print(str(traceback.print_exc()) )
|
||||
|
||||
|
||||
#/////---- ردیف های اکسل را در سامانه قانون یار شناسایی می کند و شناسه ها را در همان اکسل تولید میکند
|
||||
#//// البته با تنظیم فلگ مرتبط، امکان درج در الاستیک هم دارد
|
||||
def run_codes_to_elastic_directory(elastic, directory, output, all_codes, update_elastic = False, genrate_excel = True, col_index={}, head_top=False):
|
||||
|
||||
if not col_index :
|
||||
@@ -742,14 +757,26 @@ def run_Etebar_directory(elastic, directory, output, all_codes, update_elastic =
|
||||
print('00000 error 000000 ', code_name)
|
||||
|
||||
|
||||
def run_codes_extract_directory(directory, output, all_codes, col_index={}, head_top=False):
|
||||
def run_codes_extract_directory(directory, output, all_codes, col_index={}, head_top=False, version_key=''):
|
||||
|
||||
# List all files in the specified directory
|
||||
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
||||
for file in files :
|
||||
file_name = os.path.basename(file)
|
||||
_name = os.path.splitext(file_name)[0]
|
||||
code_name = _name.split('_')[0]
|
||||
sub_names = _name.split('_')
|
||||
code_name = sub_names[0]
|
||||
|
||||
with_history_code={}
|
||||
#--- یک زیرکد هم ذخیره بشود مثل تجارت خارجی برای کد تجارت
|
||||
if version_key and len(sub_names) > 1 and sub_names[1] != 'result' :
|
||||
with_history_code={
|
||||
"version_key": version_key,
|
||||
"label": sub_names[1],
|
||||
"sub_key": ""
|
||||
}
|
||||
print('=#'*10,' by hstory_codes genrate : ', with_history_code)
|
||||
|
||||
print('=========================== start code_name ===> ', code_name)
|
||||
w1 = text_normalizer.split_words(code_name)[0]
|
||||
log_file = output + "/log_r_"+w1+".txt"
|
||||
@@ -764,7 +791,7 @@ def run_codes_extract_directory(directory, output, all_codes, col_index={}, head
|
||||
|
||||
item_found = [item for item in all_codes if item.get("title") == code_name]
|
||||
if item_found :
|
||||
extract_codes_to_json(file_path, code_name, output + f"/{code_name}.json", col_index, head_top)
|
||||
extract_codes_to_json(file_path, code_name, output + f"/{code_name}.json", col_index, head_top, with_history_code)
|
||||
else :
|
||||
print('00000 error 000000 ', code_name)
|
||||
|
||||
|
||||
@@ -43,14 +43,23 @@ print(".... majles_codes_update_steps ......", host)
|
||||
path_base_map = "G:/Project2/gateway_php/repo/_other/"
|
||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||
|
||||
#-------------------------------------
|
||||
#------ استخراج برخی کدهای باقیمانده که اکسل آنها از قبل موجود هست و تولید فایل مناسب برای درج فایل محور در بانک مجلس
|
||||
#---
|
||||
#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")
|
||||
#-------------------------------------
|
||||
|
||||
|
||||
# -------------------------------------
|
||||
# ------ استخراج برخی کدهای باقیمانده که اکسل آنها از قبل موجود هست و تولید فایل مناسب برای درج فایل محور در بانک مجلس
|
||||
# ---
|
||||
# --- مرحله 2
|
||||
all_codes = []
|
||||
with open("./data/codes49.json", "r", encoding="utf8") as f:
|
||||
codes_1 = json.load(f)
|
||||
all_codes = codes_1
|
||||
|
||||
|
||||
col_index = {
|
||||
"row_number": 0,
|
||||
"section_title": 1,
|
||||
@@ -63,5 +72,46 @@ col_index = {
|
||||
"state_match": 8,
|
||||
}
|
||||
|
||||
### --- درج در الاستیک نمی کند
|
||||
# run_codes_to_elastic_directory( elastic, "./data/tcodes/corrected_majles/not_edit2", "./data/tcodes/corrected_majles/not_edit2/result", all_codes, False, True, col_index, False)
|
||||
# run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit2/result","./data/tcodes/corrected_majles/not_edit2/result_json",all_codes,col_index,True)
|
||||
|
||||
|
||||
# -------------------------------------
|
||||
# ------ استخراج برخی کدهای باقیمانده که اکسل آنها از قبل موجود هست و تولید فایل مناسب برای درج فایل محور در بانک مجلس
|
||||
# --- مرحله سوم : فقط برای کد تجارت - تجارت خارجی
|
||||
all_codes = []
|
||||
with open("./data/codes49.json", "r", encoding="utf8") as f:
|
||||
codes_1 = json.load(f)
|
||||
all_codes = codes_1
|
||||
|
||||
col_index = {
|
||||
"section_title" : 0,
|
||||
"ts_date" : 1,
|
||||
"qanon_title" : 2,
|
||||
"code_state" : 3,
|
||||
"row_number" : 4,
|
||||
"qanon_id" : 5,
|
||||
"section_id" : 6,
|
||||
"state_match" : 7,
|
||||
}
|
||||
|
||||
# run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit3/result","./data/tcodes/corrected_majles/not_edit3/result_json", all_codes, col_index, True, "T49_S_V1")
|
||||
# -------------------------------------
|
||||
# --- مرحله ؟؟؟؟
|
||||
|
||||
col_index = {
|
||||
"row_number": 0,
|
||||
"section_title": 1,
|
||||
"ts_date": 2,
|
||||
"qanon_title": 3,
|
||||
"code_state": 4,
|
||||
"code_label": 5,
|
||||
"qanon_id": 6,
|
||||
"section_id": 7,
|
||||
"state_match": 8,
|
||||
}
|
||||
|
||||
### --- درج در الاستیک نمی کند update_elastic = False
|
||||
# run_codes_to_elastic_directory( elastic, "./data/tcodes/corrected_majles/not_edit3", "./data/tcodes/corrected_majles/not_edit3/result", all_codes, False, True, col_index, False)
|
||||
# run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit3/result","./data/tcodes/corrected_majles/not_edit3/result_json",all_codes,col_index,True)
|
||||
|
||||
@@ -14,10 +14,6 @@ from app.common.elastic_helper import ElasticHelper
|
||||
from app.common.general_functions import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
from app.for_ai.codes_import_from_excel import (
|
||||
run_codes_extract_directory,
|
||||
run_codes_to_elastic_directory,
|
||||
)
|
||||
from app.parvande_qanon.import_qavanin_excels_to_elastic import (
|
||||
import_excel_before_to_elastic,
|
||||
import_excel_after_to_elastic,
|
||||
@@ -30,15 +26,15 @@ text_normal = TextNormalizer()
|
||||
|
||||
load_dotenv(dotenv_path="config.env")
|
||||
|
||||
host = os.getenv("HOST_160")
|
||||
password = os.getenv("HOST_160_PASS")
|
||||
# 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_H102")
|
||||
# password = os.getenv("HOST_H102_PASS")
|
||||
host = os.getenv("HOST_H102")
|
||||
password = os.getenv("HOST_H102_PASS")
|
||||
# print( "---------------->>>>>>>>>>>>>>>", host )
|
||||
|
||||
# host=os.getenv('HOST_113')
|
||||
@@ -367,7 +363,8 @@ file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
|
||||
# elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_qanon_3_base_dotic.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon')
|
||||
|
||||
|
||||
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_semantic_section", "mj_qa_semantic_section")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_semantic_section", "mj_qa_semantic_section")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_section_rule", "mj_qa_section_rule")
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import numbers
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from elasticsearch import Elasticsearch, helpers
|
||||
import json
|
||||
import re
|
||||
import zipfile
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
from app.common.general_functions import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
from app.for_ai.codes_import_from_excel import (
|
||||
run_codes_extract_directory,
|
||||
run_codes_to_elastic_directory,
|
||||
)
|
||||
from app.parvande_qanon.import_qavanin_excels_to_elastic import (
|
||||
import_excel_before_to_elastic,
|
||||
import_excel_after_to_elastic,
|
||||
import_excel_tasmimat_to_elastic,
|
||||
)
|
||||
from app.parvande_qanon.repair_qa_qanon_for_map_new import *
|
||||
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
|
||||
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_H102")
|
||||
# password = os.getenv("HOST_H102_PASS")
|
||||
# print( "---------------->>>>>>>>>>>>>>>", host )
|
||||
|
||||
# host=os.getenv('HOST_113')
|
||||
# password=os.getenv('HOST_113_PASS')
|
||||
|
||||
|
||||
print(".... majles_codes_update_steps ......", host)
|
||||
|
||||
path_base_map = "G:/Project2/gateway_php/repo/_other/"
|
||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user