majles update end

This commit is contained in:
hsafaei
2025-12-20 19:17:29 +03:30
parent 525b429d6a
commit 1e24fc6caf
3 changed files with 90 additions and 43 deletions
+79 -40
View File
@@ -71,10 +71,10 @@ elastic = ElasticHelper(host, password, "elastic", path_base_map)
# ----- حذف فیزیکی mj_qa_qanon # ----- حذف فیزیکی mj_qa_qanon
#DELETE mj_qa_qanon #DELETE mj_qa_qanon
file_path = "G:/Project2/160_dotic/majles_14040918/mj_qa_qanon.zip" file_path = "G:/Project2/160_dotic/majles_14040926/mj_qa_qanon.zip"
index_name = "mj_qa_qanon" index_name = "mj_qa_qanon"
#elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon', path_base_map+ 'majles/'+'mj_qa_qanon_new.json' ) # elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon', path_base_map+ 'majles/'+'mj_qa_qanon.json' )
# restore_correct_date_to_elastic(elastic, file_path, index_name, "G:/Project2/160_dotic/date_log_error_qaqanon.txt" ) # restore_correct_date_to_elastic(elastic, file_path, index_name, "G:/Project2/160_dotic/date_log_error_qaqanon.txt" )
@@ -84,10 +84,10 @@ index_name = "mj_qa_qanon"
# ----- حذف فیزیکی mj_df_qanon # ----- حذف فیزیکی mj_df_qanon
#DELETE mj_df_qanon #DELETE mj_df_qanon
file_path = "G:/Project2/160_dotic/majles_14040918/mj_df_qanon.zip" file_path = "G:/Project2/160_dotic/majles_14040926/mj_df_qanon.zip"
index_name = "mj_df_qanon" index_name = "mj_df_qanon"
# elastic.createIndex( 'mj_df_qanon', 'majles', 'mj_df_qanon', path_base_map+ 'majles/'+'mj_df_qanon_new.json' ) # elastic.createIndex( 'mj_df_qanon', 'majles', 'mj_df_qanon', path_base_map+ 'majles/'+'mj_df_qanon.json' )
# restore_correct_date_to_elastic(elastic, file_path, index_name, "G:/Project2/160_dotic/date_log_error_dfqanon.txt" ) # restore_correct_date_to_elastic(elastic, file_path, index_name, "G:/Project2/160_dotic/date_log_error_dfqanon.txt" )
@@ -98,19 +98,32 @@ index_name = "mj_df_qanon"
# ----- حذف فیزیکی mj_qa_section # ----- حذف فیزیکی mj_qa_section
#DELETE mj_qa_section #DELETE mj_qa_section
file_path = "G:/Project2/160_dotic/majles_14040918/mj_qa_section.zip" file_path = "G:/Project2/160_dotic/majles_14040926/mj_qa_section.zip"
index_name = "mj_qa_section" index_name = "mj_qa_section"
# elastic.createIndex( 'mj_qa_section', 'majles', 'mj_qa_section', path_base_map+ 'majles/'+'mj_qa_section_new.json' ) # elastic.createIndex( 'mj_qa_section', 'majles', 'mj_qa_section', path_base_map+ 'majles/'+'mj_qa_section.json' )
# restore_correct_date_to_elastic(elastic, file_path, index_name, "G:/Project2/160_dotic/date_log_error_qasection.txt" ) # restore_correct_date_to_elastic(elastic, file_path, index_name, "G:/Project2/160_dotic/date_log_error_qasection.txt" )
# # ---فقط برای یک بار
# # ---- حذف یک مورد اشتباه با عنوان خالی
# # POST mj_qa_section/_delete_by_query
# # {
# # "query": {
# # "term": {
# # "qanon_id": {
# # "value": "df_6914887106dba"
# # }
# # }
# # }
# # }
# ------------------------------------- # -------------------------------------
# ----- mj_rg_section # ----- mj_rg_section
file_path = "G:/Project2/160_dotic/mj_rg_section_doctic_14040824.zip" file_path = "G:/Project2/160_dotic/mj_rg_section_doctic_14040824.zip"
# elastic.createIndex( 'mj_rg_section', 'majles', 'mj_rg_section', path_base_map+ 'majles/'+'mj_qa_section_new.json') # elastic.createIndex( 'mj_rg_section', 'majles', 'mj_rg_section', path_base_map+ 'majles/'+'mj_qa_section.json')
# restore_correct_date_to_elastic(elastic, file_path, "mj_rg_section", "G:/Project2/160_dotic/date_log_error_rgsection.txt" ) # restore_correct_date_to_elastic(elastic, file_path, "mj_rg_section", "G:/Project2/160_dotic/date_log_error_rgsection.txt" )
@@ -121,8 +134,8 @@ file_path = "G:/Project2/160_dotic/mj_rg_section_doctic_14040824.zip"
file_path = "G:/Project2/160_dotic/mj_mashruh.zip" file_path = "G:/Project2/160_dotic/mj_mashruh.zip"
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh") # elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh")
elastic.createIndex( 'mj_mashruh', 'majles', 'mj_mashruh', path_base_map+ 'majles/'+'mj_mashruh.json' ) # elastic.createIndex( 'mj_mashruh', 'majles', 'mj_mashruh', path_base_map+ 'majles/'+'mj_mashruh.json' )
restore_correct_date_to_elastic(elastic, file_path, "mj_mashruh", "G:/Project2/160_dotic/date_log_error_mashruh.txt" ) # restore_correct_date_to_elastic(elastic, file_path, "mj_mashruh", "G:/Project2/160_dotic/date_log_error_mashruh.txt" )
@@ -139,8 +152,8 @@ restore_correct_date_to_elastic(elastic, file_path, "mj_mashruh", "G:/Project2/1
# ctx._source.main_type = 'قانون' # ctx._source.main_type = 'قانون'
# """, # """,
# "lang": "painless", # "lang": "painless"
# }, # }
# } # }
# elastic.updateByQueryIndex("mj_qa_qanon", body) # elastic.updateByQueryIndex("mj_qa_qanon", body)
@@ -154,8 +167,8 @@ restore_correct_date_to_elastic(elastic, file_path, "mj_mashruh", "G:/Project2/1
# ctx._source.sub_type = ctx._source.main_type; # ctx._source.sub_type = ctx._source.main_type;
# ctx._source.main_type = 'قانون' # ctx._source.main_type = 'قانون'
# """, # """,
# "lang": "painless", # "lang": "painless"
# }, # }
# } # }
# elastic.updateByQueryIndex("mj_qa_qanon", body) # elastic.updateByQueryIndex("mj_qa_qanon", body)
@@ -190,7 +203,7 @@ restore_correct_date_to_elastic(elastic, file_path, "mj_mashruh", "G:/Project2/1
# elastic.updateByQueryIndex("mj_df_qanon", body) # elastic.updateByQueryIndex("mj_df_qanon", body)
#elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040918", "mj_df_qanon", "mj_df_qanon_1_date") # elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_df_qanon", "mj_df_qanon_1_date")
# --------------------------------------------- 3 ------------------------------------------------------------------ # --------------------------------------------- 3 ------------------------------------------------------------------
@@ -198,32 +211,37 @@ restore_correct_date_to_elastic(elastic, file_path, "mj_mashruh", "G:/Project2/1
# --------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------
# --- موقت # --- موقت
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon_1_date") # elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_qanon", "mj_qa_qanon_1_date")
# -- حذف مقرره های قبلی # -- حذف مقرره های قبلی
body = {"query": {"term": {"main_type": {"value": "مقرره"}}}} # body = {"query": {"term": {"main_type": {"value": "مقرره"}}}}
# elastic.deleteByQueryIndex("mj_qa_qanon", body) # elastic.deleteByQueryIndex("mj_qa_qanon", body)
# --- موقت # --- موقت
#elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon_2_base") # elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_qanon", "mj_qa_qanon_2_base")
# ------------------------------------- # -------------------------------------
# ------------------------------------- # -------------------------------------
# --- درج داده های جدید مقرره # --- درج داده های جدید مقرره
# import_data_new_qaqanon(elastic, "G:/Project2/160_dotic/mj_qa_qanon_doctic_14040824.zip") # import_data_new_qaqanon(elastic, "G:/Project2/160_dotic/dotic_14040824/mj_qa_qanon_doctic_14040824.zip")
# -------------------------------------
# ----- انتقال داده های آراء به # ----- انتقال داده های آراء به
#### بخاطر لزوم تغییر روش کار، لازم شد محتوای آراء به اینجا منتفل شود #--- بخاطر لزوم تغییر روش کار، لازم شد محتوای آراء به اینجا منتفل شود
#### البته بقیه فراداده قبلا منتقل شده بودند #--- البته بقیه فراداده قبلا منتقل شده بودند
# file_path = 'G:/Project2/160_dotic/mj_qa_opinion_doctic_14040824.zip'
# index_name = "mj_qa_qanon" file_path = 'G:/Project2/160_dotic/dotic_14040824/mj_qa_opinion_doctic_14040824.zip'
# import_content_opinion_to_qaqanon(elastic, file_path, index_name ) # import_content_opinion_to_qaqanon(elastic, file_path, "mj_qa_qanon" )
# # -------------------------------------
# # ----- انتقال داده های مشروح مذاکرات به فهرست همه قوانین
# ??????فعلا انجام نشده # file_path = 'G:/Project2/160_dotic/mj_mashruh.zip'
# --- موقت # --- موقت
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon_3_base_dotic") # elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_qanon", "mj_qa_qanon_3_base_dotic")
# --------------------------------------------- 4 ------------------------------------------------------------------ # --------------------------------------------- 4 ------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------------------------------------------------------------------
@@ -231,8 +249,6 @@ file_before = "G:/Project2/160_dotic/duplicate_before.json"
file_after = "G:/Project2/160_dotic/duplicate_after.json" file_after = "G:/Project2/160_dotic/duplicate_after.json"
file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json" file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
# elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon', path_base_map+ 'majles/'+'mj_qa_qanon_new.json' )
# elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_qanon_3_base_dotic.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon')
# # #------------------------------------------ # # #------------------------------------------
# duplicate_list = {} # duplicate_list = {}
@@ -265,7 +281,7 @@ file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
# # --- موقت # # --- موقت
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon_4_base_excel") #elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_qanon", "mj_qa_qanon_4_base_excel")
#---------تنظیم شد mj_qa_qanon_new.json #---------تنظیم شد mj_qa_qanon_new.json
@@ -290,13 +306,13 @@ file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
#------------------------------------ #------------------------------------
#--- mj_qa_section #--- mj_qa_section
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_section", "mj_qa_section_1_base") #elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_section", "mj_qa_section_1_base")
# بررسی پر بودن main_type مجلس برای نوع اصلی/تبعی/مهذب # و تغییر به mom_type # بررسی پر بودن main_type مجلس برای نوع اصلی/تبعی/مهذب # و تغییر به mom_type
#### schema changed --> qasection_mom_type #### schema changed --> qasection_mom_type
# # # POST mj_qa_section/_update_by_query # # POST mj_qa_section/_update_by_query
# body = { # body = {
# "query": {"terms": {"main_type": ["اصلی", "تبعی"]}}, # "query": {"terms": {"main_type": ["اصلی", "تبعی"]}},
# "script": { # "script": {
@@ -305,12 +321,30 @@ file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
# ctx._source.mom_type = ctx._source.main_type; # ctx._source.mom_type = ctx._source.main_type;
# ctx._source.main_type = 'قانون' # ctx._source.main_type = 'قانون'
# """, # """,
# "lang": "painless", # "lang": "painless"
# }, # }
# } # }
# elastic.updateByQueryIndex("mj_qa_section", body) # elastic.updateByQueryIndex("mj_qa_section", body)
#-------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------
#--- پشتیبان گیری نهایی برای انتقال
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh")
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon")
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_df_qanon", "mj_df_qanon")
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_section", "mj_qa_section")
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_rg_section", "mj_rg_section")
#-------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------------
# elastic.createIndex( 'mj_qa_section-m1', 'majles', 'mj_qa_section', path_base_map+ 'majles/'+'mj_qa_section.json' )
# elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_section-m1.zip', 'mj_qa_section-m1', 'majles', False)
#-------------------------------------------------------------------------------------------------
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh") # elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh")
@@ -318,21 +352,26 @@ file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
# elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_mashruh.zip', 'mj_mashruh', 'majles', False, 'mj_mashruh') # elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_mashruh.zip', 'mj_mashruh', 'majles', False, 'mj_mashruh')
# elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon') # elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon')
# elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_qanon_base_excel.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon') # elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_qanon_base_excel.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon')
# elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon', path_base_map+ 'majles/'+'mj_qa_qanon_new.json' ) # elastic.createIndex( 'mj_qa_section', 'majles', 'mj_qa_section', path_base_map+ 'majles/'+'mj_qa_section.json' )
# elastic.restorFileToElastic2('G:/Project2/160_dotic/majles_14040918/mj_qa_qanon_4_base_excel.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon') # elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_section.zip', 'mj_qa_section', 'majles', False, 'mj_qa_section')
# elastic.createIndex( 'mj_df_qanon', 'majles', 'mj_df_qanon', path_base_map+ 'majles/'+'mj_df_qanon_new.json' ) # elastic.createIndex( 'mj_df_qanon', 'majles', 'mj_df_qanon', path_base_map+ 'majles/'+'mj_df_qanon.json' )
# elastic.restorFileToElastic2('G:/Project2/160_dotic/majles_14040918/mj_df_qanon_1_date.zip', 'mj_df_qanon', 'majles', False, 'mj_df_qanon') # elastic.restorFileToElastic2('G:/Project2/160_dotic/majles_14040926/mj_df_qanon_1_date.zip', 'mj_df_qanon', 'majles', False, 'mj_df_qanon')
# elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon', path_base_map+ 'majles/'+'mj_qa_qanon.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/160_dotic", "mj_qa_semantic_section", "mj_qa_semantic_section")
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh")
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_section", "mj_qa_section")
@@ -615,6 +615,7 @@ def import_excel_tasmimat_to_elastic(elastic, path_file, index_name_o, duplicate
"term": term, "term": term,
"ts_date": ts_date, "ts_date": ts_date,
"ts_ref": ts_ref, "ts_ref": ts_ref,
"meet_number": number,
"description": description, "description": description,
"content": content "content": content
} }
@@ -100,7 +100,7 @@ def correct_qanon_date_json(data, error_list):
data_new.append(item) data_new.append(item)
return data_new return data_new
def normal_data_json(data): def normal_mashruh_data_json(data):
data_new = [] data_new = []
for item in data: for item in data:
id = item["_id"] id = item["_id"]
@@ -114,6 +114,12 @@ def normal_data_json(data):
if 'title' in item["_source"] : if 'title' in item["_source"] :
item["_source"]['title'] = text_normal.normalize_qanon(item["_source"]['title']) item["_source"]['title'] = text_normal.normalize_qanon(item["_source"]['title'])
if 'content_type' in item["_source"] :
item["_source"]['content_type'] = text_normal.normalize_qanon(item["_source"]['content_type']).strip()
if 'title_type' in item["_source"] :
item["_source"]['title_type'] = text_normal.normalize_qanon(item["_source"]['title_type']).strip()
if "talker" in item["_source"]: if "talker" in item["_source"]:
talker = item["_source"]["talker"] talker = item["_source"]["talker"]
if 'organ' in talker : if 'organ' in talker :
@@ -148,7 +154,8 @@ def restore_correct_date_to_elastic(elastic, file_path, index_name, file_error='
data_new = correct_qanon_date_json(data, error_list) data_new = correct_qanon_date_json(data, error_list)
if index_name == 'mj_mashruh' : if index_name == 'mj_mashruh' :
data_new = normal_data_json(data_new) data_new = normal_mashruh_data_json(data_new)
elastic.importJsonDataToElastic(data_new, index_name, [], True) elastic.importJsonDataToElastic(data_new, index_name, [], True)
counter += len(data) counter += len(data)
# print('-'*10, 'len()', str(counter) + '/ ' + str(len(data)) + ' , ' +str(len(data_new)) ) # print('-'*10, 'len()', str(counter) + '/ ' + str(len(data)) + ' , ' +str(len(data_new)) )