import majles...
This commit is contained in:
@@ -349,7 +349,7 @@ class ElasticHelper:
|
|||||||
# - دادهها را از فایل ZIP به Elasticsearch بازیابی میکند
|
# - دادهها را از فایل ZIP به Elasticsearch بازیابی میکند
|
||||||
# -----------------------------end----------------------------
|
# -----------------------------end----------------------------
|
||||||
def restorFileToElastic(
|
def restorFileToElastic(
|
||||||
self, path_back, index_name, app_key="", queryDelete=True, map_name=""
|
self, path_back, index_name, app_key="", queryDelete=True, map_name="", mapping_file_path = ""
|
||||||
):
|
):
|
||||||
if not os.path.exists(path_back):
|
if not os.path.exists(path_back):
|
||||||
print(" **** error *** path not exist: ", path_back)
|
print(" **** error *** path not exist: ", path_back)
|
||||||
@@ -362,14 +362,14 @@ class ElasticHelper:
|
|||||||
if queryDelete:
|
if queryDelete:
|
||||||
# اگر وجود داشته باشد، از کاربر برای حذفش سوال میکند
|
# اگر وجود داشته باشد، از کاربر برای حذفش سوال میکند
|
||||||
if self.deleteIndex(index_name):
|
if self.deleteIndex(index_name):
|
||||||
self.createIndex(index_name, app_key, map_name)
|
self.createIndex(index_name, app_key, map_name, mapping_file_path)
|
||||||
self.zipFileToElastic(file_path, index_name)
|
self.zipFileToElastic(file_path, index_name)
|
||||||
else: # اگر وجود داشته باشد پرش می کند و کاری نمیکند
|
else: # اگر وجود داشته باشد پرش می کند و کاری نمیکند
|
||||||
self.createIndex(index_name, app_key, map_name)
|
self.createIndex(index_name, app_key, map_name, mapping_file_path)
|
||||||
self.zipFileToElastic(file_path, index_name)
|
self.zipFileToElastic(file_path, index_name)
|
||||||
|
|
||||||
def restorFileToElastic2(
|
def restorFileToElastic2(
|
||||||
self, path_file, index_name, app_key="", queryDelete=True, map_name=""
|
self, path_file, index_name, app_key="", queryDelete=True, map_name="", mapping_file_path = ""
|
||||||
):
|
):
|
||||||
if not os.path.exists(path_file):
|
if not os.path.exists(path_file):
|
||||||
print(" **** error *** path not exist: ", path_file)
|
print(" **** error *** path not exist: ", path_file)
|
||||||
@@ -382,10 +382,10 @@ class ElasticHelper:
|
|||||||
if queryDelete:
|
if queryDelete:
|
||||||
# اگر وجود داشته باشد، از کاربر برای حذفش سوال میکند
|
# اگر وجود داشته باشد، از کاربر برای حذفش سوال میکند
|
||||||
if self.deleteIndex(index_name):
|
if self.deleteIndex(index_name):
|
||||||
self.createIndex(index_name, app_key, map_name)
|
self.createIndex(index_name, app_key, map_name, mapping_file_path)
|
||||||
self.zipFileToElastic(file_path, index_name)
|
self.zipFileToElastic(file_path, index_name)
|
||||||
else: # اگر وجود داشته باشد پرش می کند و کاری نمیکند
|
else: # اگر وجود داشته باشد پرش می کند و کاری نمیکند
|
||||||
self.createIndex(index_name, app_key, map_name)
|
self.createIndex(index_name, app_key, map_name, mapping_file_path)
|
||||||
self.zipFileToElastic(file_path, index_name)
|
self.zipFileToElastic(file_path, index_name)
|
||||||
|
|
||||||
# ----------------------------start---------------------------
|
# ----------------------------start---------------------------
|
||||||
|
|||||||
@@ -158,6 +158,13 @@ def split_words(text) :
|
|||||||
words = re.split(r"[\t\n\r\.\"«»\)\(\]\[,;،؛ \-!?:]+", text)
|
words = re.split(r"[\t\n\r\.\"«»\)\(\]\[,;،؛ \-!?:]+", text)
|
||||||
return words
|
return words
|
||||||
|
|
||||||
|
def is_number_string(value):
|
||||||
|
try:
|
||||||
|
float(value)
|
||||||
|
return True
|
||||||
|
except ValueError:
|
||||||
|
return False
|
||||||
|
|
||||||
def normalHeadingTitle(text, last_path = '', keyTitles=[]):
|
def normalHeadingTitle(text, last_path = '', keyTitles=[]):
|
||||||
global _normalizer
|
global _normalizer
|
||||||
lines = text.split('\n')
|
lines = text.split('\n')
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import re
|
|||||||
import traceback
|
import traceback
|
||||||
import json
|
import json
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import copy
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@@ -590,7 +591,7 @@ def importCodesToElastic(elastic, file_excel, index_name_o, tcode_label, file_lo
|
|||||||
|
|
||||||
file.close()
|
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 :
|
if head_top :
|
||||||
@@ -646,21 +647,34 @@ def extract_codes_to_json( file_excel, tcode_label, file_json, col_index, head_t
|
|||||||
|
|
||||||
|
|
||||||
data={}
|
data={}
|
||||||
# ذخیره کد در الاستیک برای شناسه های یافت شده
|
# ذخیره کد برای شناسه های یافت شده
|
||||||
if section_id and section_id != 0:
|
if section_id and section_id != 0:
|
||||||
|
|
||||||
_source = {}
|
_source = {}
|
||||||
|
history_codes= []
|
||||||
|
sub_key = ''
|
||||||
if code_state :
|
if code_state :
|
||||||
_source["tcode_mains"] = [tcode_label]
|
_source["tcode_mains"] = [tcode_label]
|
||||||
|
sub_key = 'main'
|
||||||
else :
|
else :
|
||||||
_source["tcode_subs"] = [tcode_label]
|
_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={
|
data={
|
||||||
'id':section_id,
|
'id':section_id,
|
||||||
'_source' : _source,
|
'_source' : _source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bulk_data.append(data)
|
bulk_data.append(data)
|
||||||
|
|
||||||
with open(file_json, "w", encoding="utf8") as f:
|
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('######################## Exception error --- row_number : ' , str(row_number), '/', str(count) , ' ***' , str(e) )
|
||||||
print(str(traceback.print_exc()) )
|
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):
|
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 :
|
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)
|
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
|
# List all files in the specified directory
|
||||||
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
|
||||||
for file in files :
|
for file in files :
|
||||||
file_name = os.path.basename(file)
|
file_name = os.path.basename(file)
|
||||||
_name = os.path.splitext(file_name)[0]
|
_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)
|
print('=========================== start code_name ===> ', code_name)
|
||||||
w1 = text_normalizer.split_words(code_name)[0]
|
w1 = text_normalizer.split_words(code_name)[0]
|
||||||
log_file = output + "/log_r_"+w1+".txt"
|
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]
|
item_found = [item for item in all_codes if item.get("title") == code_name]
|
||||||
if item_found :
|
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 :
|
else :
|
||||||
print('00000 error 000000 ', code_name)
|
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/"
|
path_base_map = "G:/Project2/gateway_php/repo/_other/"
|
||||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
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 = []
|
all_codes = []
|
||||||
with open("./data/codes49.json", "r", encoding="utf8") as f:
|
with open("./data/codes49.json", "r", encoding="utf8") as f:
|
||||||
codes_1 = json.load(f)
|
codes_1 = json.load(f)
|
||||||
all_codes = codes_1
|
all_codes = codes_1
|
||||||
|
|
||||||
|
|
||||||
col_index = {
|
col_index = {
|
||||||
"row_number": 0,
|
"row_number": 0,
|
||||||
"section_title": 1,
|
"section_title": 1,
|
||||||
@@ -63,5 +72,46 @@ col_index = {
|
|||||||
"state_match": 8,
|
"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_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)
|
# 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.general_functions import *
|
||||||
from app.common.text_normalizer import TextNormalizer
|
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 (
|
from app.parvande_qanon.import_qavanin_excels_to_elastic import (
|
||||||
import_excel_before_to_elastic,
|
import_excel_before_to_elastic,
|
||||||
import_excel_after_to_elastic,
|
import_excel_after_to_elastic,
|
||||||
@@ -30,15 +26,15 @@ text_normal = TextNormalizer()
|
|||||||
|
|
||||||
load_dotenv(dotenv_path="config.env")
|
load_dotenv(dotenv_path="config.env")
|
||||||
|
|
||||||
host = os.getenv("HOST_160")
|
# host = os.getenv("HOST_160")
|
||||||
password = os.getenv("HOST_160_PASS")
|
# password = os.getenv("HOST_160_PASS")
|
||||||
|
|
||||||
# host = os.getenv("HOST_112")
|
# host = os.getenv("HOST_112")
|
||||||
# password = os.getenv("HOST_112_PASS")
|
# password = os.getenv("HOST_112_PASS")
|
||||||
|
|
||||||
|
|
||||||
# host = os.getenv("HOST_H102")
|
host = os.getenv("HOST_H102")
|
||||||
# password = os.getenv("HOST_H102_PASS")
|
password = os.getenv("HOST_H102_PASS")
|
||||||
# print( "---------------->>>>>>>>>>>>>>>", host )
|
# print( "---------------->>>>>>>>>>>>>>>", host )
|
||||||
|
|
||||||
# host=os.getenv('HOST_113')
|
# 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.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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,457 @@
|
|||||||
|
import mariadb
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
import uuid
|
||||||
|
import pandas as pd
|
||||||
|
import zipfile
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
from tqdm import tqdm
|
||||||
|
|
||||||
|
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.majles_options import *
|
||||||
|
|
||||||
|
|
||||||
|
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")
|
||||||
|
|
||||||
|
# print(host)
|
||||||
|
# print(password)
|
||||||
|
|
||||||
|
|
||||||
|
path_base_map = (
|
||||||
|
"G:\Project2\gateaway_py\elastic_backend/elastic_backend/app/schemas/mappings/"
|
||||||
|
)
|
||||||
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||||
|
text_normalize = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
|
log_file = None
|
||||||
|
|
||||||
|
|
||||||
|
def extract_zip_files(elastic, filezip, file_import_ids, file_type="groups"):
|
||||||
|
|
||||||
|
bulk_data = []
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
|
jump_ids = []
|
||||||
|
if os.path.exists(file_import_ids):
|
||||||
|
with open(file_import_ids, "r") as f:
|
||||||
|
jump_ids = f.readlines()
|
||||||
|
|
||||||
|
fileNo = 0
|
||||||
|
with zipfile.ZipFile(filezip, "r") as zObject:
|
||||||
|
fileNo += 1
|
||||||
|
print(
|
||||||
|
"=" * 10,
|
||||||
|
" zip fileNo: ",
|
||||||
|
fileNo,
|
||||||
|
" ) | File Numbers:",
|
||||||
|
len(zObject.namelist()),
|
||||||
|
"=" * 10,
|
||||||
|
)
|
||||||
|
|
||||||
|
counter = 0
|
||||||
|
files = zObject.namelist()
|
||||||
|
|
||||||
|
index_name_o = "mj_qa_context"
|
||||||
|
|
||||||
|
for filename in tqdm(files, total=len(files), desc="groups "):
|
||||||
|
|
||||||
|
qanon_id = (
|
||||||
|
filename.replace("parents_for_", "")
|
||||||
|
.replace("context_for_", "")
|
||||||
|
.replace("terms_for_", "")
|
||||||
|
.replace("rule_for_", "")
|
||||||
|
.replace(".json", "")
|
||||||
|
)
|
||||||
|
|
||||||
|
if qanon_id in jump_ids:
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(f"***** {file_type} : ", index_name_o, "=>", filename, " qanon_id=" , qanon_id)
|
||||||
|
with zObject.open(filename) as file:
|
||||||
|
data = json.loads(file.read())
|
||||||
|
|
||||||
|
try:
|
||||||
|
if file_type == "groups":
|
||||||
|
index_name_o = "mj_qa_context"
|
||||||
|
bulk_data, total_count = import_groups_qanon(
|
||||||
|
elastic,
|
||||||
|
qanon_id,
|
||||||
|
data,
|
||||||
|
bulk_data,
|
||||||
|
total_count,
|
||||||
|
index_name_o,
|
||||||
|
)
|
||||||
|
jump_ids.append(qanon_id)
|
||||||
|
|
||||||
|
if file_type == "contexts":
|
||||||
|
index_name_o = "mj_qa_context"
|
||||||
|
bulk_data, total_count = import_contexts_qanon(
|
||||||
|
elastic,
|
||||||
|
qanon_id,
|
||||||
|
data,
|
||||||
|
bulk_data,
|
||||||
|
total_count,
|
||||||
|
index_name_o,
|
||||||
|
)
|
||||||
|
jump_ids.append(qanon_id)
|
||||||
|
|
||||||
|
if file_type == "terms":
|
||||||
|
index_name_o = "mj_qa_context"
|
||||||
|
bulk_data, total_count = import_terms_qanon(
|
||||||
|
elastic,
|
||||||
|
qanon_id,
|
||||||
|
data,
|
||||||
|
bulk_data,
|
||||||
|
total_count,
|
||||||
|
index_name_o,
|
||||||
|
)
|
||||||
|
jump_ids.append(qanon_id)
|
||||||
|
|
||||||
|
if file_type == "rules":
|
||||||
|
index_name_o = "mj_qa_rule"
|
||||||
|
bulk_data, total_count = import_rules_qanon(
|
||||||
|
elastic,
|
||||||
|
qanon_id,
|
||||||
|
data,
|
||||||
|
bulk_data,
|
||||||
|
total_count,
|
||||||
|
index_name_o,
|
||||||
|
)
|
||||||
|
jump_ids.append(qanon_id)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("error in file " + qanon_id + str(e))
|
||||||
|
|
||||||
|
if len(bulk_data) > 0:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, " to_elastic , total=" + str(total_count))
|
||||||
|
if file_type == "rules" or file_type == "groups":
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
else :
|
||||||
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
with open(file_import_ids, "w") as f:
|
||||||
|
f.write("\n".join(jump_ids))
|
||||||
|
|
||||||
|
print("end success import_to_elastic")
|
||||||
|
|
||||||
|
|
||||||
|
def import_groups_qanon(elastic, qanon_id, data, bulk_data, total_count, index_name_o):
|
||||||
|
|
||||||
|
chuk_order = 0
|
||||||
|
index_name_i = "mj_qa_section"
|
||||||
|
|
||||||
|
for item in data["chunks"]:
|
||||||
|
if len(item) == 0:
|
||||||
|
continue
|
||||||
|
|
||||||
|
section_mom_id = item[0]
|
||||||
|
eid = item[0]
|
||||||
|
section_ids = item
|
||||||
|
chuk_order = chuk_order + 1
|
||||||
|
qanon_title = ""
|
||||||
|
qanon_etebar = ""
|
||||||
|
state_etebar = ""
|
||||||
|
ts_date = None
|
||||||
|
ts_ref = ""
|
||||||
|
title = ""
|
||||||
|
content = ""
|
||||||
|
|
||||||
|
for section_id in section_ids:
|
||||||
|
source = None
|
||||||
|
try:
|
||||||
|
res = elastic.get_document(index_name_i, section_id)
|
||||||
|
source = res["_source"]
|
||||||
|
except:
|
||||||
|
error = (
|
||||||
|
" section_id not found in qa_section :"
|
||||||
|
+ qanon_id
|
||||||
|
+ ":"
|
||||||
|
+ section_id
|
||||||
|
)
|
||||||
|
if log_file:
|
||||||
|
log_file.write(5 * "*" + error + "\n")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not qanon_title and "qanon_etebar" in source:
|
||||||
|
qanon_title = source["qanon_title"]
|
||||||
|
if not qanon_etebar and "qanon_etebar" in source:
|
||||||
|
qanon_etebar = source["qanon_etebar"]
|
||||||
|
if not ts_date and "ts_date" in source:
|
||||||
|
ts_date = source["ts_date"]
|
||||||
|
if not ts_ref and "ts_ref" in source:
|
||||||
|
ts_ref = source["ts_ref"]
|
||||||
|
|
||||||
|
if section_id == section_mom_id:
|
||||||
|
if "state_etebar" in source:
|
||||||
|
state_etebar = source["state_etebar"]
|
||||||
|
|
||||||
|
if "other_info" in source:
|
||||||
|
title = source["other_info"]["full_path"]
|
||||||
|
|
||||||
|
if content:
|
||||||
|
content += "\n"
|
||||||
|
content += source["content"]
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"section_mom_id": section_mom_id,
|
||||||
|
"version_key": "base_1",
|
||||||
|
"qanon_id": qanon_id,
|
||||||
|
"qanon_title": qanon_title,
|
||||||
|
"qanon_etebar": qanon_etebar,
|
||||||
|
"state_etebar": state_etebar,
|
||||||
|
"ts_date": ts_date,
|
||||||
|
"title": title,
|
||||||
|
"ts_ref": ts_ref,
|
||||||
|
"chuk_order": chuk_order,
|
||||||
|
"content": content,
|
||||||
|
"group_section_ids": section_ids,
|
||||||
|
"time_create": int(round(time.time() * 1000)),
|
||||||
|
}
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, "to_elastic , total=" + str(total_count), ", id=" + eid)
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
return bulk_data, total_count
|
||||||
|
|
||||||
|
|
||||||
|
def import_contexts_qanon(
|
||||||
|
elastic, qanon_id, data, bulk_data, total_count, index_name_o
|
||||||
|
):
|
||||||
|
chuk_order = 0
|
||||||
|
|
||||||
|
for key, value in data.items():
|
||||||
|
|
||||||
|
section_mom_id = key
|
||||||
|
eid = key
|
||||||
|
|
||||||
|
context = []
|
||||||
|
|
||||||
|
for item in value:
|
||||||
|
items = item.split("=")
|
||||||
|
|
||||||
|
title = ""
|
||||||
|
content = ""
|
||||||
|
context_type = "ابهام"
|
||||||
|
|
||||||
|
if len(items) == 2:
|
||||||
|
title = items[0]
|
||||||
|
content = items[1]
|
||||||
|
else:
|
||||||
|
content = item
|
||||||
|
context_type = "ابهام-نامشخص"
|
||||||
|
|
||||||
|
context.append(
|
||||||
|
{"title": title, "content": content, "context_type": context_type}
|
||||||
|
)
|
||||||
|
|
||||||
|
data = {"context": context}
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, "to_elastic , total=" + str(total_count), ", id=" + eid)
|
||||||
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
return bulk_data, total_count
|
||||||
|
|
||||||
|
|
||||||
|
def import_terms_qanon(elastic, qanon_id, data, bulk_data, total_count, index_name_o):
|
||||||
|
chuk_order = 0
|
||||||
|
terms = data["terms"]
|
||||||
|
for item in terms:
|
||||||
|
|
||||||
|
title = item["term"]
|
||||||
|
content = item["definition"]
|
||||||
|
article_ids = item["article_ids"]
|
||||||
|
context_type = "تعریف"
|
||||||
|
|
||||||
|
for context_id in article_ids:
|
||||||
|
|
||||||
|
source = None
|
||||||
|
try:
|
||||||
|
res = elastic.get_document(index_name_o, context_id)
|
||||||
|
source = res["_source"]
|
||||||
|
except:
|
||||||
|
error = (
|
||||||
|
" context_id not found in :"
|
||||||
|
+ index_name_o
|
||||||
|
+ " "
|
||||||
|
+ qanon_id
|
||||||
|
+ ":"
|
||||||
|
+ context_id
|
||||||
|
)
|
||||||
|
if log_file:
|
||||||
|
log_file.write(5 * "*" + error + "\n")
|
||||||
|
continue
|
||||||
|
|
||||||
|
eid = context_id
|
||||||
|
context = []
|
||||||
|
if "context" in source:
|
||||||
|
context = source["context"]
|
||||||
|
|
||||||
|
context.append(
|
||||||
|
{"title": title, "content": content, "context_type": context_type}
|
||||||
|
)
|
||||||
|
|
||||||
|
data = {"context": context}
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print(
|
||||||
|
"=" * 10, "to_elastic , total=" + str(total_count), ", id=" + eid
|
||||||
|
)
|
||||||
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
return bulk_data, total_count
|
||||||
|
|
||||||
|
|
||||||
|
def import_rules_qanon(elastic, qanon_id, data, bulk_data, total_count, index_name_o):
|
||||||
|
|
||||||
|
index_name_i = "mj_qa_context"
|
||||||
|
|
||||||
|
for key, value in data.items():
|
||||||
|
|
||||||
|
context_id = key
|
||||||
|
|
||||||
|
qanon_title = ""
|
||||||
|
qanon_etebar = ""
|
||||||
|
state_etebar = ""
|
||||||
|
ts_date = None
|
||||||
|
ts_ref = ""
|
||||||
|
group_section_ids = []
|
||||||
|
|
||||||
|
source = None
|
||||||
|
try:
|
||||||
|
res = elastic.get_document(index_name_i, context_id)
|
||||||
|
source = res["_source"]
|
||||||
|
except:
|
||||||
|
error = " section_mom_id not found in qa_context :" + qanon_id + ":" + context_id
|
||||||
|
if log_file:
|
||||||
|
log_file.write(5 * "*" + error + "\n")
|
||||||
|
continue
|
||||||
|
|
||||||
|
if "qanon_etebar" in source:
|
||||||
|
qanon_title = source["qanon_title"]
|
||||||
|
if "qanon_etebar" in source:
|
||||||
|
qanon_etebar = source["qanon_etebar"]
|
||||||
|
if "ts_date" in source:
|
||||||
|
ts_date = source["ts_date"]
|
||||||
|
if "ts_ref" in source:
|
||||||
|
ts_ref = source["ts_ref"]
|
||||||
|
if "state_etebar" in source:
|
||||||
|
state_etebar = source["state_etebar"]
|
||||||
|
|
||||||
|
if "group_section_ids" in source:
|
||||||
|
group_section_ids = source["group_section_ids"]
|
||||||
|
|
||||||
|
rule_order = 0
|
||||||
|
for item in value:
|
||||||
|
|
||||||
|
rule_id = item["id"]
|
||||||
|
content = item["content"]
|
||||||
|
rule_type = item["main_type"]
|
||||||
|
rule_order = rule_order + 1
|
||||||
|
|
||||||
|
eid = rule_id
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"context_id": context_id,
|
||||||
|
"version_key": "base_1",
|
||||||
|
"qanon_id": qanon_id,
|
||||||
|
"qanon_title": qanon_title,
|
||||||
|
"qanon_etebar": qanon_etebar,
|
||||||
|
"state_etebar": state_etebar,
|
||||||
|
"ts_date": ts_date,
|
||||||
|
"ts_ref": ts_ref,
|
||||||
|
"rule_order": rule_order,
|
||||||
|
"rule_type": rule_type,
|
||||||
|
"content": content,
|
||||||
|
"group_section_ids": group_section_ids,
|
||||||
|
"time_create": int(round(time.time() * 1000)),
|
||||||
|
}
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, "to_elastic , total=" + str(total_count), ", id=" + eid)
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
return bulk_data, total_count
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# ### ----------------------------------------------
|
||||||
|
# data_key = "groups"
|
||||||
|
# log_file = open(f"G:/Project2/102_gpu/log_{data_key}_1.txt", mode="w", encoding="utf8")
|
||||||
|
# filezip = f"G:/Project2/102_gpu/{data_key}.zip"
|
||||||
|
# file_import_ids = f"G:/Project2/102_gpu/{data_key}_import_ids.txt"
|
||||||
|
# extract_zip_files(elastic, filezip, file_import_ids, data_key)
|
||||||
|
# log_file.close()
|
||||||
|
|
||||||
|
# ### ----------------------------------------------
|
||||||
|
# data_key = "contexts"
|
||||||
|
# log_file = open(f"G:/Project2/102_gpu/log_{data_key}_1.txt", mode="w", encoding="utf8")
|
||||||
|
# filezip = f"G:/Project2/102_gpu/{data_key}.zip"
|
||||||
|
# file_import_ids = f"G:/Project2/102_gpu/{data_key}_import_ids.txt"
|
||||||
|
# extract_zip_files(elastic, filezip, file_import_ids, data_key)
|
||||||
|
# log_file.close()
|
||||||
|
|
||||||
|
# ### ----------------------------------------------
|
||||||
|
# data_key = "terms"
|
||||||
|
# log_file = open(
|
||||||
|
# f"G:/Project2/102_gpu/log_{data_key}_1.txt", mode="w", encoding="utf8"
|
||||||
|
# )
|
||||||
|
# filezip = f"G:/Project2/102_gpu/{data_key}.zip"
|
||||||
|
# file_import_ids = f"G:/Project2/102_gpu/{data_key}_import_ids.txt"
|
||||||
|
# extract_zip_files(elastic, filezip, file_import_ids, data_key)
|
||||||
|
# log_file.close()
|
||||||
|
|
||||||
|
# ### ----------------------------------------------
|
||||||
|
# data_key = "rules"
|
||||||
|
# log_file = open(
|
||||||
|
# f"G:/Project2/102_gpu/log_{data_key}_1.txt", mode="w", encoding="utf8"
|
||||||
|
# )
|
||||||
|
# filezip = f"G:/Project2/102_gpu/{data_key}.zip"
|
||||||
|
# file_import_ids = f"G:/Project2/102_gpu/{data_key}_import_ids.txt"
|
||||||
|
# extract_zip_files(elastic, filezip, file_import_ids, data_key)
|
||||||
|
# log_file.close()
|
||||||
|
|
||||||
|
|
||||||
|
# ### ----------------------------------------------
|
||||||
|
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_context", "mj_qa_context")
|
||||||
|
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_rule", "mj_qa_rule")
|
||||||
|
|
||||||
|
# mapping_file_path = "G:/\Project2/_back/_to_majles/14041022/src/repo/_other/majles/mj_qa_context.json"
|
||||||
|
# elastic.restorFileToElastic2('G:/Project2/102_gpu/mj_qa_context.zip', 'mj_qa_context', 'majles', False, 'mj_qa_context', mapping_file_path)
|
||||||
|
|
||||||
|
# mapping_file_path = "G:/\Project2/_back/_to_majles/14041022/src/repo/_other/majles/mj_qa_rule.json"
|
||||||
|
# elastic.restorFileToElastic2('G:/Project2/102_gpu/mj_qa_rule.zip', 'mj_qa_rule', 'majles', False, 'mj_qa_rule', mapping_file_path)
|
||||||
|
|
||||||
|
# ### ----------------------------------------------
|
||||||
@@ -0,0 +1,623 @@
|
|||||||
|
import mariadb
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
import uuid
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
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.majles_options import *
|
||||||
|
|
||||||
|
|
||||||
|
load_dotenv(dotenv_path="config.env")
|
||||||
|
|
||||||
|
host = os.getenv("HOST_160")
|
||||||
|
# host = os.getenv("HOST_160_LOCAL")
|
||||||
|
password = os.getenv("HOST_160_PASS")
|
||||||
|
|
||||||
|
# host = os.getenv("HOST_60")
|
||||||
|
# password = os.getenv("HOST_60_PASS")
|
||||||
|
|
||||||
|
# print(host)
|
||||||
|
# print(password)
|
||||||
|
|
||||||
|
|
||||||
|
path_base_map = (
|
||||||
|
"G:\Project2\gateaway_py\elastic_backend/elastic_backend/app/schemas/mappings/"
|
||||||
|
)
|
||||||
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||||
|
text_normalize = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
|
def import_simple_list_to_elastic(
|
||||||
|
elastic,
|
||||||
|
items,
|
||||||
|
prefix_id,
|
||||||
|
tree_label,
|
||||||
|
tree_key,
|
||||||
|
group_key="",
|
||||||
|
index_name_o="gn_tree",
|
||||||
|
):
|
||||||
|
|
||||||
|
bulk_data = []
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
|
t1 = datetime.datetime.now()
|
||||||
|
print(t1)
|
||||||
|
i = 0
|
||||||
|
for item in items:
|
||||||
|
# print(i)
|
||||||
|
i = i + 1
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not item:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = prefix_id + str(i).zfill(5)
|
||||||
|
# eid = uuid.uuid4().hex[:8]
|
||||||
|
|
||||||
|
eid = id
|
||||||
|
title = item.strip()
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
parent_id = "0"
|
||||||
|
child_order = i
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "base_1",
|
||||||
|
"tree_key": tree_key,
|
||||||
|
"tree_label": tree_label,
|
||||||
|
"main_type": "list",
|
||||||
|
"group_key": group_key,
|
||||||
|
"title": title,
|
||||||
|
"parent_id": parent_id,
|
||||||
|
"child_order": child_order,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print(
|
||||||
|
"=" * 10,
|
||||||
|
"to_elastic , total=" + str(total_count),
|
||||||
|
str(i) + ", id=" + eid,
|
||||||
|
)
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
|
||||||
|
if len(bulk_data) > 0:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, " to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
print("end success import_to_elastic")
|
||||||
|
t2 = datetime.datetime.now()
|
||||||
|
print(t2 - t1)
|
||||||
|
|
||||||
|
|
||||||
|
def import_project_to_elastic(
|
||||||
|
cursor, elastic, project_id, project_title, index_name_o="gn_tree"
|
||||||
|
):
|
||||||
|
|
||||||
|
query = f"""
|
||||||
|
SELECT id, title, parent, child_order, meta, tags from tlist.tl_subjects
|
||||||
|
where project_id={project_id}
|
||||||
|
ORDER BY parent, child_order
|
||||||
|
"""
|
||||||
|
# print('-'*10)
|
||||||
|
# print(query)
|
||||||
|
# print('-'*10)
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
parent_nodes = {}
|
||||||
|
bulk_data = []
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
|
t1 = datetime.datetime.now()
|
||||||
|
print(t1)
|
||||||
|
i = 0
|
||||||
|
while 1:
|
||||||
|
# print(i)
|
||||||
|
i = i + 1
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not row:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = row[0]
|
||||||
|
# eid = uuid.uuid4().hex[:8]
|
||||||
|
eid = "gnt" + str(id).zfill(5)
|
||||||
|
title = row[1]
|
||||||
|
|
||||||
|
if title is None: # داده های خراب
|
||||||
|
continue
|
||||||
|
title = row[1].strip()
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
parent = row[2]
|
||||||
|
parent_id = 0
|
||||||
|
if parent != 0:
|
||||||
|
parent_id = "gnt" + str(parent).zfill(5)
|
||||||
|
child_order = row[3]
|
||||||
|
meta = row[4]
|
||||||
|
tags = row[5]
|
||||||
|
|
||||||
|
meta_info = {}
|
||||||
|
if meta:
|
||||||
|
meta_info["id1"] = str(meta)
|
||||||
|
|
||||||
|
tags_list = []
|
||||||
|
if tags:
|
||||||
|
for tt in tags.strip().split(","):
|
||||||
|
if tt and not tt in tags_list:
|
||||||
|
tags_list.append(tt)
|
||||||
|
|
||||||
|
main_type_key = "tree" + str(project_id)
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "base_1",
|
||||||
|
"tree_key": main_type_key,
|
||||||
|
"tree_label": project_title,
|
||||||
|
"main_type": "tree",
|
||||||
|
# "group_key" : "",
|
||||||
|
"title": title,
|
||||||
|
"parent_id": parent_id,
|
||||||
|
"child_order": child_order,
|
||||||
|
"tags": tags_list,
|
||||||
|
"meta_info": meta_info,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print(
|
||||||
|
"=" * 10,
|
||||||
|
"to_elastic , total=" + str(total_count),
|
||||||
|
str(i) + ", id=" + eid,
|
||||||
|
)
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
|
||||||
|
if len(bulk_data) > 0:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, " to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
print("end success import_to_elastic")
|
||||||
|
t2 = datetime.datetime.now()
|
||||||
|
print(t2 - t1)
|
||||||
|
|
||||||
|
|
||||||
|
def import_tlist_projects():
|
||||||
|
|
||||||
|
config_env = load_dotenv(dotenv_path="./config.env")
|
||||||
|
MYSQL_username = os.getenv("MYSQL_username")
|
||||||
|
MYSQL_root_password = os.getenv("MYSQL_root_password")
|
||||||
|
MYSQL_port = os.getenv("MYSQL_port")
|
||||||
|
# MYSQL_host = os.getenv("MYSQL_import_host")
|
||||||
|
# MYSQL_host = os.getenv("MYSQL_import_host_60")
|
||||||
|
MYSQL_host = os.getenv("MYSQL_import_host_160")
|
||||||
|
cnx = mariadb.connect(user="root", password=MYSQL_root_password, host=MYSQL_host)
|
||||||
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
|
query = "select id, title from tlist.tl_projects"
|
||||||
|
cursor.execute(query)
|
||||||
|
list_projects = []
|
||||||
|
while 1:
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not row:
|
||||||
|
break
|
||||||
|
|
||||||
|
pid = row[0] # "id"
|
||||||
|
title = row[1] # "title"
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
# print(title)
|
||||||
|
|
||||||
|
# پلانهای استفاده نشده در مجلس
|
||||||
|
if pid >= 100 and pid <= 200:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# کدهای تنقیح مجلس که در جای دیگه اضافه میشود
|
||||||
|
if pid == 4 or pid == 5 or pid == 8:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# موضوعات درختی قدیم و نهادهای حاکمیتی که دیگه جایگزین با 6 شد
|
||||||
|
if pid == 1 or pid == 2:
|
||||||
|
continue
|
||||||
|
|
||||||
|
list_projects.append({"id": pid, "title": title})
|
||||||
|
|
||||||
|
for item in list_projects:
|
||||||
|
print("*" * 100)
|
||||||
|
print(item)
|
||||||
|
import_project_to_elastic(cursor, elastic, item["id"], item["title"], "gn_tree")
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
|
||||||
|
def import_option_to_elastic(
|
||||||
|
elastic,
|
||||||
|
main_key,
|
||||||
|
main_label,
|
||||||
|
group_key="majles_base",
|
||||||
|
eid="",
|
||||||
|
index_name_o="gn_option",
|
||||||
|
):
|
||||||
|
res = get_options(main_key)
|
||||||
|
titles = []
|
||||||
|
for item in res :
|
||||||
|
title = item["value"]
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
titles.append(title)
|
||||||
|
|
||||||
|
if not eid:
|
||||||
|
eid = uuid.uuid4().hex[:8]
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
|
||||||
|
|
||||||
|
def import_option_base_list(elastic):
|
||||||
|
op_list = [
|
||||||
|
{
|
||||||
|
"main_key": "qasection_before_info_plan_type",
|
||||||
|
"main_label": "پرونده - تقدیم - نوع پیش نویس",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "qasection_before_info_discuss_type",
|
||||||
|
"main_label": "پرونده - نوع شور ",
|
||||||
|
},
|
||||||
|
{"main_key": "qasection_letters_type", "main_label": "پرونده - نوع نامه نگاری"},
|
||||||
|
{
|
||||||
|
"main_key": "qasection_before_info_commission_type",
|
||||||
|
"main_label": "پرونده - نوع کمیسیون ",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "qasection_before_info_commission",
|
||||||
|
"main_label": "پروند - عنوان کمیسیونها",
|
||||||
|
},
|
||||||
|
{"main_key": "rgsection_tsref", "main_label": "مقررات - مرجع تصویب ها"},
|
||||||
|
{"main_key": "qasection_tsref", "main_label": "قانون - مرجع تصویب ها"},
|
||||||
|
{
|
||||||
|
"group_key": "majles_it_base",
|
||||||
|
"main_key": "qasection_qanon_etebar",
|
||||||
|
"main_label": "وضعیت اعتبار قانون",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"group_key": "majles_it_base",
|
||||||
|
"main_key": "qasection_state_etebar",
|
||||||
|
"main_label": "وضعیت اعتبار جزء قانون",
|
||||||
|
},
|
||||||
|
{"main_key": "qasection_doc_tags", "main_label": "انواع قانون برای فهرست سازی"},
|
||||||
|
{"main_key": "qasection_doc_states", "main_label": "صحت سنجی - وضعیت قانون"},
|
||||||
|
{
|
||||||
|
"main_key": "qasection_title_type",
|
||||||
|
"main_label": "شناسنامه قانون - نوع عنوان",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "qasection_main_type",
|
||||||
|
"main_label": "شناسنامه قانون - نوع اصلی-تبعی",
|
||||||
|
},
|
||||||
|
{"main_key": "qasection_sub_type", "main_label": "شناسنامه قانون - نوع فرعی"},
|
||||||
|
{"main_key": "rgsection_sub_type", "main_label": "شناسنامه مقررات - نوع فرعی"},
|
||||||
|
{"main_key": "qaopinion_main_type", "main_label": "شناسنامه آراء - نوع اصلی"},
|
||||||
|
{"main_key": "qaopinion_sub_type", "main_label": "شناسنامه آراء - نوع فرعی"},
|
||||||
|
{"main_key": "qaopinion_tsref", "main_label": "شناسنامه آراء - مرجع تصویب ها"},
|
||||||
|
{
|
||||||
|
"group_key": "majles_it_base",
|
||||||
|
"main_key": "dfqanon_effect_type",
|
||||||
|
"main_label": "ورود قانون - نوع اثرگذاری",
|
||||||
|
},
|
||||||
|
{"main_key": "relation_type", "main_label": "ارتباطات قانون - نوع ارتباط"},
|
||||||
|
{
|
||||||
|
"group_key": "majles_it_base",
|
||||||
|
"main_key": "relation_to",
|
||||||
|
"main_label": "ارتباطات قانون - نوق مقصد",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"group_key": "majles_it_base",
|
||||||
|
"main_key": "relation_from",
|
||||||
|
"main_label": "ارتباطات قانون - نوع مبدا",
|
||||||
|
},
|
||||||
|
{"main_key": "mashruh_majles", "main_label": "مشروح مذاکرات - نوع مجلس"},
|
||||||
|
{"main_key": "qasection_mom_type", "main_label": "نوع اصلی-تبعی-مهذب"},
|
||||||
|
|
||||||
|
# {
|
||||||
|
# "main_key": "ref_id",
|
||||||
|
# "main_label": ""
|
||||||
|
# },
|
||||||
|
# {
|
||||||
|
# "main_key": "diff_type",
|
||||||
|
# "main_label": ""
|
||||||
|
# },
|
||||||
|
]
|
||||||
|
|
||||||
|
number = 0
|
||||||
|
for op in op_list:
|
||||||
|
number = number + 1
|
||||||
|
print(op["main_key"])
|
||||||
|
eid = "mb_op_" + str(number)
|
||||||
|
group_key = "عناوین انتخابی فرمها"
|
||||||
|
if "group_key" in op:
|
||||||
|
group_key = op["group_key"]
|
||||||
|
|
||||||
|
import_option_to_elastic(
|
||||||
|
elastic, op["main_key"], op["main_label"], group_key, eid
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def import_option_codes(elastic, index_name_o="gn_option"):
|
||||||
|
|
||||||
|
###-------------------------------------------
|
||||||
|
titles = get_codes54()
|
||||||
|
eid = "mb_op_codes54"
|
||||||
|
group_key = "کدهای تنقیح"
|
||||||
|
main_key = "codes54"
|
||||||
|
main_label = "کدهای تنقیح 54 باب"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
###-------------------------------------------
|
||||||
|
titles = get_codes51()
|
||||||
|
eid = "mb_op_codes51"
|
||||||
|
group_key = "کدهای تنقیح"
|
||||||
|
main_key = "codes51"
|
||||||
|
main_label = "کدهای تنقیح 51 باب"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
###-------------------------------------------
|
||||||
|
titles = get_codes50()
|
||||||
|
eid = "mb_op_codes50"
|
||||||
|
group_key = "کدهای تنقیح"
|
||||||
|
main_key = "codes50"
|
||||||
|
main_label = "کدهای تنقیح 50 باب"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
###-------------------------------------------
|
||||||
|
titles = get_codes49()
|
||||||
|
eid = "mb_op_codes49"
|
||||||
|
group_key = "کدهای تنقیح"
|
||||||
|
main_key = "codes49"
|
||||||
|
main_label = "کدهای تنقیح 49 باب"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
###-------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
def import_option_parleman_members(elastic, index_name_o="gn_option"):
|
||||||
|
|
||||||
|
excel_file1 = "data/qavanin_files/list_فهرست نمایندگان دوره 9 تا 12.xlsx"
|
||||||
|
df = pd.read_excel(excel_file1, sheet_name=1)
|
||||||
|
column_names = df.columns.tolist()
|
||||||
|
rows_list = df.to_dict(orient="records")
|
||||||
|
print(column_names)
|
||||||
|
prev_term = 0
|
||||||
|
pm_list = []
|
||||||
|
|
||||||
|
for row in rows_list:
|
||||||
|
code = row[column_names[0]]
|
||||||
|
lname = row[column_names[1]]
|
||||||
|
name = row[column_names[2]]
|
||||||
|
print(code)
|
||||||
|
|
||||||
|
if code is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
code = str(code)
|
||||||
|
if not is_number_string(code) or code == "810102" or len(code) != len("77101"):
|
||||||
|
continue
|
||||||
|
|
||||||
|
id = int(code)
|
||||||
|
scode = code
|
||||||
|
sterm = scode[0:2]
|
||||||
|
if sterm == "99":
|
||||||
|
sterm = "9"
|
||||||
|
elif sterm == "88":
|
||||||
|
sterm = "8"
|
||||||
|
elif sterm == "77":
|
||||||
|
sterm = "7"
|
||||||
|
elif sterm == "66":
|
||||||
|
sterm = "6"
|
||||||
|
elif sterm == "55":
|
||||||
|
sterm = "5"
|
||||||
|
elif sterm == "44":
|
||||||
|
sterm = "4"
|
||||||
|
elif sterm == "33":
|
||||||
|
sterm = "3"
|
||||||
|
elif sterm == "22":
|
||||||
|
sterm = "2"
|
||||||
|
|
||||||
|
term = int(sterm)
|
||||||
|
if prev_term == 0:
|
||||||
|
prev_term = term
|
||||||
|
|
||||||
|
if term != prev_term and pm_list:
|
||||||
|
|
||||||
|
main_key = "pm_" + str(prev_term)
|
||||||
|
main_label = "نمایندگان دوره " + str(prev_term)
|
||||||
|
group_key = "نمایندگان ادوار مجلس"
|
||||||
|
main_type = "table"
|
||||||
|
object_columns = [
|
||||||
|
{"key": "title", "title": "نام نماینده", "width": 8},
|
||||||
|
{"key": "id", "title": "کد نماینده", "width": 4},
|
||||||
|
]
|
||||||
|
|
||||||
|
eid = "mj_" + main_key
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"object_columns": object_columns,
|
||||||
|
"object_values": pm_list,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
pm_list = []
|
||||||
|
prev_term = term
|
||||||
|
|
||||||
|
title = lname + " " + name
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
pm_list.append({"id": str(id), "title": title})
|
||||||
|
|
||||||
|
if pm_list:
|
||||||
|
|
||||||
|
main_key = "pm_" + str(prev_term)
|
||||||
|
main_label = "نمایندگان دوره " + str(prev_term)
|
||||||
|
group_key = "نمایندگان ادوار مجلس"
|
||||||
|
main_type = "table"
|
||||||
|
object_columns = [
|
||||||
|
{"key": "title", "title": "نام نماینده", "width": 8},
|
||||||
|
{"key": "id", "title": "کد نماینده", "width": 4},
|
||||||
|
]
|
||||||
|
|
||||||
|
eid = "mj_" + main_key
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"main_type": main_type,
|
||||||
|
"group_key": group_key,
|
||||||
|
"object_columns": object_columns,
|
||||||
|
"object_values": pm_list,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
index_name_o="gn_option"
|
||||||
|
|
||||||
|
|
||||||
|
# ---مرحله اول
|
||||||
|
# import_tlist_projects()
|
||||||
|
|
||||||
|
import_option_base_list(elastic)
|
||||||
|
|
||||||
|
import_option_parleman_members(elastic)
|
||||||
|
|
||||||
|
import_option_codes(elastic)
|
||||||
|
|
||||||
|
|
||||||
|
###-------------------------------------------
|
||||||
|
res = get_organs()
|
||||||
|
titles = []
|
||||||
|
for title in res :
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
titles.append(title)
|
||||||
|
|
||||||
|
eid = "mb_op_organs1"
|
||||||
|
group_key = "عناوین انتخابی فرمها"
|
||||||
|
main_key = "mj_qa_organs"
|
||||||
|
main_label = "سازمانها و نهادهای حاکمیتی"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
###------------------------------------------
|
||||||
|
res = [
|
||||||
|
"دفتر مقام معظم رهبری",
|
||||||
|
"دفتر رئیس جمهور",
|
||||||
|
"دفتر ریاست قوه قضائیه",
|
||||||
|
"دفتر ریاست مجلس شورای اسلامی",
|
||||||
|
"دبیرخانه مجمع تشخیص مصلحت نظام",
|
||||||
|
"دبیرخانه شورای نگهبان",
|
||||||
|
"دفتر معاون اول رئیس جمهور",
|
||||||
|
"معاونت امور مجلس رئیس جمهور",
|
||||||
|
"معاونت حقوقی رئیس جمهور",
|
||||||
|
"کلیه وزارتخانه ها،سازمان ها، مؤسسات دولتی،نهادهای انقلاب اسلامی و استانداری های سراسر کشور",
|
||||||
|
"دیوان محاسبات کشور",
|
||||||
|
"دفتر هیأت دولت",
|
||||||
|
"دبیرخانه شورای اطلاع رسانی دولت",
|
||||||
|
"معاونت امور تقنینی معاونت امور مجلس ریاست جمهوری",
|
||||||
|
"معاونت قوانین مجلس شورای اسلامی",
|
||||||
|
"معاونت نظارت مجلس شورای اسلامی",
|
||||||
|
"معاونت ارتباطات و اطلاع رسانی دفتر رئیس جمهور",
|
||||||
|
"معاونت تدوین، تنقیح و انتشار قوانین و مقررات نهاد ریاست جمهوری",
|
||||||
|
"اداره کل پیگیری طرح ها و لوایح معاونت امور مجلس ریاست جمهوری",
|
||||||
|
"اداره کل اسناد و اطلاع رسانی قوانین مجلس شورای اسلامی",
|
||||||
|
"اداره کل امور تقنینی و کمیسیونها مجلس شورای اسلامی",
|
||||||
|
"سامانه ملی قوانین و مقررات جمهوری اسلامی ایران",
|
||||||
|
"روزنامه رسمی جمهوری اسلامی ایران",
|
||||||
|
]
|
||||||
|
titles = []
|
||||||
|
for title in res :
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
titles.append(title)
|
||||||
|
|
||||||
|
eid = "mb_organ_1"
|
||||||
|
group_key = "عناوین انتخابی برنامه"
|
||||||
|
main_key = "organ_defualt"
|
||||||
|
main_label = "سازمانهای پیش فرض قانون جدید"
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,407 @@
|
|||||||
|
import mariadb
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
import os
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
import uuid
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
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.monir_options import (
|
||||||
|
get_public_options,
|
||||||
|
get_monir_options
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
load_dotenv(dotenv_path="config.env")
|
||||||
|
|
||||||
|
# host = os.getenv("HOST_160")
|
||||||
|
# host = os.getenv("HOST_160_LOCAL")
|
||||||
|
# password = os.getenv("HOST_160_PASS")
|
||||||
|
|
||||||
|
host = os.getenv("HOST_60")
|
||||||
|
password = os.getenv("HOST_60_PASS")
|
||||||
|
|
||||||
|
# print(host)
|
||||||
|
# print(password)
|
||||||
|
|
||||||
|
|
||||||
|
path_base_map = (
|
||||||
|
"G:\Project2\gateaway_py\elastic_backend/elastic_backend/app/schemas/mappings/"
|
||||||
|
)
|
||||||
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||||
|
text_normalize = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
|
def import_simple_list_to_elastic(
|
||||||
|
elastic,
|
||||||
|
items,
|
||||||
|
prefix_id,
|
||||||
|
tree_label,
|
||||||
|
tree_key,
|
||||||
|
group_key="",
|
||||||
|
index_name_o="gn_tree",
|
||||||
|
):
|
||||||
|
|
||||||
|
bulk_data = []
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
|
t1 = datetime.datetime.now()
|
||||||
|
print(t1)
|
||||||
|
i = 0
|
||||||
|
for item in items:
|
||||||
|
# print(i)
|
||||||
|
i = i + 1
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not item:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = prefix_id + str(i).zfill(5)
|
||||||
|
# eid = uuid.uuid4().hex[:8]
|
||||||
|
|
||||||
|
eid = id
|
||||||
|
title = item.strip()
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
parent_id = "0"
|
||||||
|
child_order = i
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "base_1",
|
||||||
|
"tree_key": tree_key,
|
||||||
|
"tree_label": tree_label,
|
||||||
|
"main_type": "list",
|
||||||
|
"group_key": group_key,
|
||||||
|
"title": title,
|
||||||
|
"parent_id": parent_id,
|
||||||
|
"child_order": child_order,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print(
|
||||||
|
"=" * 10,
|
||||||
|
"to_elastic , total=" + str(total_count),
|
||||||
|
str(i) + ", id=" + eid,
|
||||||
|
)
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
|
||||||
|
if len(bulk_data) > 0:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, " to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
print("end success import_to_elastic")
|
||||||
|
t2 = datetime.datetime.now()
|
||||||
|
print(t2 - t1)
|
||||||
|
|
||||||
|
|
||||||
|
def import_project_to_elastic(
|
||||||
|
cursor, elastic, project_id, project_title, index_name_o="gn_tree"
|
||||||
|
):
|
||||||
|
|
||||||
|
query = f"""
|
||||||
|
SELECT id, title, parent, child_order, meta, tags from tlist.tl_subjects
|
||||||
|
where project_id={project_id}
|
||||||
|
ORDER BY parent, child_order
|
||||||
|
"""
|
||||||
|
# print('-'*10)
|
||||||
|
# print(query)
|
||||||
|
# print('-'*10)
|
||||||
|
cursor.execute(query)
|
||||||
|
|
||||||
|
parent_nodes = {}
|
||||||
|
bulk_data = []
|
||||||
|
total_count = 0
|
||||||
|
|
||||||
|
t1 = datetime.datetime.now()
|
||||||
|
print(t1)
|
||||||
|
i = 0
|
||||||
|
while 1:
|
||||||
|
# print(i)
|
||||||
|
i = i + 1
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not row:
|
||||||
|
break
|
||||||
|
|
||||||
|
id = row[0]
|
||||||
|
# eid = uuid.uuid4().hex[:8]
|
||||||
|
eid = "gnt" + str(id).zfill(5)
|
||||||
|
title = row[1]
|
||||||
|
|
||||||
|
if title is None: # داده های خراب
|
||||||
|
continue
|
||||||
|
title = row[1].strip()
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
parent = row[2]
|
||||||
|
parent_id = 0
|
||||||
|
if parent != 0:
|
||||||
|
parent_id = "gnt" + str(parent).zfill(5)
|
||||||
|
child_order = row[3]
|
||||||
|
meta = row[4]
|
||||||
|
tags = row[5]
|
||||||
|
|
||||||
|
meta_info = {}
|
||||||
|
if meta:
|
||||||
|
meta_info["id1"] = str(meta)
|
||||||
|
|
||||||
|
tags_list = []
|
||||||
|
if tags:
|
||||||
|
for tt in tags.strip().split(","):
|
||||||
|
if tt and not tt in tags_list:
|
||||||
|
tags_list.append(tt)
|
||||||
|
|
||||||
|
main_type_key = "tree" + str(project_id)
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "base_1",
|
||||||
|
"tree_key": main_type_key,
|
||||||
|
"tree_label": project_title,
|
||||||
|
"main_type": "tree",
|
||||||
|
# "group_key" : "",
|
||||||
|
"title": title,
|
||||||
|
"parent_id": parent_id,
|
||||||
|
"child_order": child_order,
|
||||||
|
"tags": tags_list,
|
||||||
|
"meta_info": meta_info,
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(bulk_data) >= 100:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print(
|
||||||
|
"=" * 10,
|
||||||
|
"to_elastic , total=" + str(total_count),
|
||||||
|
str(i) + ", id=" + eid,
|
||||||
|
)
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
bulk_data.append({"_id": eid, "_source": data})
|
||||||
|
|
||||||
|
if len(bulk_data) > 0:
|
||||||
|
total_count += len(bulk_data)
|
||||||
|
print("=" * 10, " to_elastic , total=" + str(total_count))
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
bulk_data = []
|
||||||
|
|
||||||
|
print("end success import_to_elastic")
|
||||||
|
t2 = datetime.datetime.now()
|
||||||
|
print(t2 - t1)
|
||||||
|
|
||||||
|
|
||||||
|
def import_tlist_projects():
|
||||||
|
|
||||||
|
config_env = load_dotenv(dotenv_path="./config.env")
|
||||||
|
MYSQL_username = os.getenv("MYSQL_username")
|
||||||
|
MYSQL_root_password = os.getenv("MYSQL_root_password")
|
||||||
|
MYSQL_port = os.getenv("MYSQL_port")
|
||||||
|
# MYSQL_host = os.getenv("MYSQL_import_host")
|
||||||
|
MYSQL_host = os.getenv("MYSQL_import_host_60")
|
||||||
|
# MYSQL_host = os.getenv("MYSQL_import_host_160")
|
||||||
|
cnx = mariadb.connect(user="root", password=MYSQL_root_password, host=MYSQL_host)
|
||||||
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
|
query = "select id, title from tlist.tl_projects"
|
||||||
|
cursor.execute(query)
|
||||||
|
list_projects = []
|
||||||
|
while 1:
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if not row:
|
||||||
|
break
|
||||||
|
|
||||||
|
pid = row[0] # "id"
|
||||||
|
title = row[1] # "title"
|
||||||
|
title = text_normalize.normalize_qanon(title)
|
||||||
|
# print(title)
|
||||||
|
|
||||||
|
# فهرست های تستی همفهمی
|
||||||
|
if pid == 4 or pid == 5 or pid == 6:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# استانها و شهرها که در ایندکس دیگر ذخیره می شود
|
||||||
|
if pid == 1000:
|
||||||
|
continue
|
||||||
|
|
||||||
|
list_projects.append({"id": pid, "title": title})
|
||||||
|
|
||||||
|
for item in list_projects:
|
||||||
|
print("*" * 100)
|
||||||
|
print(item)
|
||||||
|
import_project_to_elastic(cursor, elastic, item["id"], item["title"], "gn_tree")
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
|
||||||
|
def import_option_to_elastic(
|
||||||
|
elastic,
|
||||||
|
main_key,
|
||||||
|
main_label,
|
||||||
|
group_key="monir_base",
|
||||||
|
eid="",
|
||||||
|
index_name_o="gn_option",
|
||||||
|
):
|
||||||
|
res = get_public_options(main_key)
|
||||||
|
if not res :
|
||||||
|
res = get_monir_options(main_key)
|
||||||
|
|
||||||
|
titles = [item["value"] for item in res]
|
||||||
|
if not eid:
|
||||||
|
eid = uuid.uuid4().hex[:8]
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"main_type": "list_simple",
|
||||||
|
"titles": titles,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
|
||||||
|
|
||||||
|
def import_option_base_list(elastic):
|
||||||
|
op_list = [
|
||||||
|
{
|
||||||
|
"main_key": "calendar_main_type",
|
||||||
|
"main_label": "تقویم- نوع اصلی",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "calendar_media",
|
||||||
|
"main_label": "تقویم - رسانه دارد؟",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "calendar_domain",
|
||||||
|
"main_label": "تقویم - حوزه درخواست",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "calendar_format",
|
||||||
|
"main_label": "تقویم - قالب جلسه",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "calendar_exec",
|
||||||
|
"main_label": "تقویم - وضعیت برگزاری",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "calendar_accept",
|
||||||
|
"main_label": "تقویم - وضعیت پذیرش",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"main_key": "sanad_steps",
|
||||||
|
"main_label": "مراحل نگارش سند",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "search_amplify",
|
||||||
|
"main_label": "انواع جستجوی تقویتی",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "sanad_meta-permit",
|
||||||
|
"main_label": "سطوح دسترسی داده",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "sanad_format",
|
||||||
|
"main_label": "قالب های جلسه",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "fish_take_type",
|
||||||
|
"main_label": "فیش - نوع برداشت",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "fish_text_verb",
|
||||||
|
"main_label": "فیش - نوع فعل",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"main_key": "note_take_type",
|
||||||
|
"main_label": "یادداشت - نوع برداشت",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
number = 0
|
||||||
|
for op in op_list:
|
||||||
|
number = number + 1
|
||||||
|
print(op["main_key"])
|
||||||
|
eid = "mn_op_" + str(number)
|
||||||
|
group_key = "عناوین انتخابی برنامه"
|
||||||
|
if "group_key" in op:
|
||||||
|
group_key = op["group_key"]
|
||||||
|
|
||||||
|
import_option_to_elastic(
|
||||||
|
elastic, op["main_key"], op["main_label"], group_key, eid
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def import_option_ostan_shahr(elastic, index_name_o="gn_option"):
|
||||||
|
|
||||||
|
file_path = './data/ostan.txt'
|
||||||
|
|
||||||
|
lines = []
|
||||||
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
|
||||||
|
print(len(lines))
|
||||||
|
|
||||||
|
ostan_dic={}
|
||||||
|
number = 0
|
||||||
|
for line in lines:
|
||||||
|
items = line.strip('\n').split('\t')
|
||||||
|
# print(items)
|
||||||
|
number +=1
|
||||||
|
if len(items) != 2 :
|
||||||
|
continue
|
||||||
|
ostan=items[0]
|
||||||
|
ostan = text_normalize.normalize_qanon(ostan)
|
||||||
|
shahr=items[1]
|
||||||
|
shahr = text_normalize.normalize_qanon(shahr)
|
||||||
|
|
||||||
|
if ostan not in ostan_dic:
|
||||||
|
ostan_dic[ostan] = []
|
||||||
|
|
||||||
|
ostan_dic[ostan].append(shahr)
|
||||||
|
|
||||||
|
|
||||||
|
number = 0
|
||||||
|
for key, value in ostan_dic.items():
|
||||||
|
|
||||||
|
number = number + 1
|
||||||
|
ostan = key
|
||||||
|
shahrs = value
|
||||||
|
|
||||||
|
eid = 'iros_' + str(number)
|
||||||
|
main_key = "iros_" + str(number)
|
||||||
|
main_label = "شهرهای استان " + ostan
|
||||||
|
group_key = "استان و شهرهای ایران"
|
||||||
|
main_type = "list_simple"
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"version_key": "b1",
|
||||||
|
"main_key": main_key,
|
||||||
|
"main_label": main_label,
|
||||||
|
"group_key": group_key,
|
||||||
|
"titles": shahrs,
|
||||||
|
}
|
||||||
|
elastic.es.index(index=index_name_o, id=eid, document=data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
# ---مرحله اول
|
||||||
|
# import_tlist_projects()
|
||||||
|
|
||||||
|
# import_option_base_list(elastic)
|
||||||
|
|
||||||
|
import_option_ostan_shahr(elastic)
|
||||||
|
|
||||||
@@ -0,0 +1,118 @@
|
|||||||
|
def get_public_options(key, add_all_item=False):
|
||||||
|
options = []
|
||||||
|
|
||||||
|
if key == "calendar_main_type":
|
||||||
|
options = [
|
||||||
|
{"value": "اصلی"},
|
||||||
|
{"value": "پشتیبان"},
|
||||||
|
]
|
||||||
|
elif key == "calendar_media":
|
||||||
|
options = [
|
||||||
|
{"value": "دارد"},
|
||||||
|
{"value": "ندارد"},
|
||||||
|
]
|
||||||
|
elif key == "calendar_domain":
|
||||||
|
options = [
|
||||||
|
{"value": "مدیریت"},
|
||||||
|
{"value": "ارتباطات"},
|
||||||
|
{"value": "فرهنگستان"},
|
||||||
|
{"value": "حوزوی"},
|
||||||
|
{"value": "دانشگاهی"},
|
||||||
|
{"value": "نظام"},
|
||||||
|
{"value": "عمومی"},
|
||||||
|
]
|
||||||
|
elif key == "calendar_format":
|
||||||
|
options = [
|
||||||
|
{"value": "منبر", "title": "منبر"},
|
||||||
|
{"value": "سخنرانی", "title": "سخنرانی"},
|
||||||
|
{"value": "مشاوره", "title": "مشاوره"},
|
||||||
|
{"value": "خطبه عقد", "title": "خطبه عقد"},
|
||||||
|
{"value": "کتاب", "title": "کتاب"},
|
||||||
|
{"value": "گفتگو", "title": "گفتگو"},
|
||||||
|
{"value": "دیدار", "title": "دیدار"},
|
||||||
|
{"value": "درس خارج", "title": "درس خارج"},
|
||||||
|
{"value": "مصاحبه", "title": "مصاحبه"},
|
||||||
|
{"value": "سایر", "title": "سایر"},
|
||||||
|
]
|
||||||
|
elif key == "calendar_exec":
|
||||||
|
options = [
|
||||||
|
{"value": "برگزار شد", "title": "برگزار شد"},
|
||||||
|
{"value": "لغو از طرف استاد", "title": "لغو از طرف استاد"},
|
||||||
|
{"value": "لغو از طرف دعوت کننده", "title": "لغو از طرف دعوت کننده"},
|
||||||
|
]
|
||||||
|
elif key == "calendar_accept":
|
||||||
|
options = [
|
||||||
|
{"value": "منتظر بررسی", "title": "منتظر بررسی"},
|
||||||
|
{"value": "پذیرش", "title": "پذیرش"},
|
||||||
|
{"value": "عدم پذیرش", "title": "عدم پذیرش"},
|
||||||
|
]
|
||||||
|
|
||||||
|
if add_all_item:
|
||||||
|
options.insert(0, {"value": "all", "title": "All"})
|
||||||
|
|
||||||
|
return options
|
||||||
|
|
||||||
|
|
||||||
|
def get_monir_options(key: str, add_all_item: bool = False):
|
||||||
|
options_map = {
|
||||||
|
"sanad_steps": [
|
||||||
|
{"value": "پیاده تایپ"},
|
||||||
|
{"value": "تطبیق"},
|
||||||
|
{"value": "کنترل"},
|
||||||
|
{"value": "سند پژوهشی"},
|
||||||
|
{"value": "سند اولیه"},
|
||||||
|
{"value": "ویرایش 1"},
|
||||||
|
{"value": "متن سایت"},
|
||||||
|
{"value": "ویرایش 2"},
|
||||||
|
{"value": "سند ثانویه"},
|
||||||
|
],
|
||||||
|
"search_amplify": [
|
||||||
|
{"value": "رویکرد تعریفی", "title": "رویکرد تعریفی"},
|
||||||
|
{"value": "رویکرد استدلالی", "title": "رویکرد استدلالی"},
|
||||||
|
{"value": "رویکرد تمثیلی", "title": "رویکرد تمثیلی"},
|
||||||
|
{
|
||||||
|
"value": "تنظیم بیشتر...",
|
||||||
|
"title": "تنظیم بیشتر...",
|
||||||
|
"type": "AmplifySearch",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"sanad_meta-permit": [
|
||||||
|
{"value": "public", "title": "عمومی"},
|
||||||
|
{"value": "p1", "title": "تخصصی کم"},
|
||||||
|
{"value": "p2", "title": "تخصصی معمولی"},
|
||||||
|
{"value": "p3", "title": "تخصصی متوسط"},
|
||||||
|
{"value": "p4", "title": "تخصصی بالا"},
|
||||||
|
{"value": "p5", "title": "تخصصی چالشی بالا"},
|
||||||
|
],
|
||||||
|
"sanad_format": [
|
||||||
|
{"value": "جلسه علمی", "title": "جلسه علمی"},
|
||||||
|
{"value": "سخنرانی", "title": "سخنرانی"},
|
||||||
|
{"value": "منبر", "title": "منبر"},
|
||||||
|
{"value": "کتاب", "title": "کتاب"},
|
||||||
|
{"value": "مقاله", "title": "مقاله"},
|
||||||
|
{"value": "سایر", "title": "سایر"},
|
||||||
|
],
|
||||||
|
"fish_take_type": [
|
||||||
|
{"value": "ابهام و سوال", "title": "ابهام و سوال"},
|
||||||
|
{"value": "رفع ابهام و تشریح", "title": "رفع ابهام و تشریح"},
|
||||||
|
{"value": "سایر", "title": "سایر"},
|
||||||
|
],
|
||||||
|
"fish_text_verb": [
|
||||||
|
{"value": "نقد", "title": "نقد"},
|
||||||
|
{"value": "استدلال", "title": "استدلال"},
|
||||||
|
{"value": "تایید", "title": "تایید"},
|
||||||
|
{"value": "سوال", "title": "سوال"},
|
||||||
|
],
|
||||||
|
"note_take_type": [
|
||||||
|
{"value": "ابهام و سوال", "title": "ابهام و سوال"},
|
||||||
|
{"value": "رفع ابهام و تشریح", "title": "رفع ابهام و تشریح"},
|
||||||
|
{"value": "نقد", "title": "نقد"},
|
||||||
|
{"value": "استدلال", "title": "استدلال"},
|
||||||
|
{"value": "تعریف", "title": "تعریف"},
|
||||||
|
{"value": "سایر", "title": "سایر"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
opts = options_map.get(key, [])
|
||||||
|
if add_all_item:
|
||||||
|
opts.append({"value": "All", "title": "All"})
|
||||||
|
return opts
|
||||||
@@ -19,8 +19,8 @@ load_dotenv(dotenv_path="config.env")
|
|||||||
# host = os.getenv("HOST_160")
|
# host = os.getenv("HOST_160")
|
||||||
# password = os.getenv("HOST_160_PASS")
|
# password = os.getenv("HOST_160_PASS")
|
||||||
|
|
||||||
host=os.getenv('HOST_112')
|
# host=os.getenv('HOST_112')
|
||||||
password=os.getenv('HOST_112_PASS')
|
# password=os.getenv('HOST_112_PASS')
|
||||||
|
|
||||||
# host=os.getenv('HOST_113')
|
# host=os.getenv('HOST_113')
|
||||||
# password=os.getenv('HOST_113_PASS')
|
# password=os.getenv('HOST_113_PASS')
|
||||||
@@ -37,8 +37,8 @@ password=os.getenv('HOST_112_PASS')
|
|||||||
# host=os.getenv('HOST_80')
|
# host=os.getenv('HOST_80')
|
||||||
# password=os.getenv('HOST_80_PASS')
|
# password=os.getenv('HOST_80_PASS')
|
||||||
|
|
||||||
# host=os.getenv('HOST_133')
|
host=os.getenv('HOST_133')
|
||||||
# password=os.getenv('HOST_133_PASS')
|
password=os.getenv('HOST_133_PASS')
|
||||||
|
|
||||||
|
|
||||||
print(host)
|
print(host)
|
||||||
@@ -99,6 +99,8 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
|||||||
# elastic.backupIndexToZipfile("G:/Project2/111", "mn_crition")
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mn_crition")
|
||||||
# moveDataset1(elastic, "G:/Project2/111/gn_dataset_14031125.zip", "gn_dataset2")
|
# moveDataset1(elastic, "G:/Project2/111/gn_dataset_14031125.zip", "gn_dataset2")
|
||||||
|
|
||||||
|
# elastic.restorFileToElastic2('G:/Project2/111/mn_crition.zip', 'mn_crition', 'monir', False, 'mn_critions')
|
||||||
|
|
||||||
# -------------------------------------------------------
|
# -------------------------------------------------------
|
||||||
## backup from hamfahmi.ir
|
## backup from hamfahmi.ir
|
||||||
# -------------------------------------------------------
|
# -------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user