401 lines
15 KiB
Python
401 lines
15 KiB
Python
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.parvande_qanon.s2_import_qavanin_excels_to_elastic import (
|
|
import_excel_before_to_elastic,
|
|
import_excel_after_to_elastic,
|
|
import_excel_tasmimat_to_elastic,
|
|
)
|
|
from app.majles.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)
|
|
|
|
|
|
# -------------------------------------
|
|
# ----- یک بار فقط
|
|
# ----- پشتیبان گیری از داده های جدید داتیک
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_rg_section_temp", "mj_rg_section_doctic_14040824")
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_section_temp", "mj_qa_section_doctic_14040824")
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_opinion_temp", "mj_qa_opinion_doctic_14040824")
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon_temp", "mj_qa_qanon_doctic_14040824")
|
|
|
|
|
|
# ------------------------------------------ 1 ---------------------------------------------------------------------
|
|
# ###### اصلاح تاریخ فارسی به ذخیره سازی استاندارد date
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
|
|
# -------------------------------------
|
|
# ----- mj_qa_qanon
|
|
|
|
# ----- حذف فیزیکی mj_qa_qanon
|
|
#DELETE mj_qa_qanon
|
|
|
|
file_path = "G:/Project2/160_dotic/majles_14040926/mj_qa_qanon.zip"
|
|
index_name = "mj_qa_qanon"
|
|
|
|
# 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" )
|
|
|
|
|
|
# -------------------------------------
|
|
# ----- mj_df_qanon
|
|
|
|
# ----- حذف فیزیکی mj_df_qanon
|
|
#DELETE mj_df_qanon
|
|
|
|
file_path = "G:/Project2/160_dotic/majles_14040926/mj_df_qanon.zip"
|
|
index_name = "mj_df_qanon"
|
|
|
|
# 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" )
|
|
|
|
|
|
# -------------------------------------
|
|
# ----- mj_qa_section
|
|
#### ------>> expire_date, ts_date, ref_state.qanon_date, ref_state.effect_date
|
|
|
|
# ----- حذف فیزیکی mj_qa_section
|
|
#DELETE mj_qa_section
|
|
|
|
file_path = "G:/Project2/160_dotic/majles_14040926/mj_qa_section.zip"
|
|
index_name = "mj_qa_section"
|
|
|
|
# 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" )
|
|
|
|
|
|
# # ---فقط برای یک بار
|
|
# # ---- حذف یک مورد اشتباه با عنوان خالی
|
|
# # POST mj_qa_section/_delete_by_query
|
|
# # {
|
|
# # "query": {
|
|
# # "term": {
|
|
# # "qanon_id": {
|
|
# # "value": "df_6914887106dba"
|
|
# # }
|
|
# # }
|
|
# # }
|
|
# # }
|
|
|
|
# -------------------------------------
|
|
# ----- mj_rg_section
|
|
|
|
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.json')
|
|
# restore_correct_date_to_elastic(elastic, file_path, "mj_rg_section", "G:/Project2/160_dotic/date_log_error_rgsection.txt" )
|
|
|
|
|
|
|
|
|
|
# -------------------------------------
|
|
# ----- mj_mashruh
|
|
|
|
file_path = "G:/Project2/160_dotic/mj_mashruh.zip"
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh")
|
|
# 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" )
|
|
|
|
|
|
|
|
# --------------------------------------------- 1 ------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
# --- مواردی از قانونهای جدید که فیلد زیر را ندارند باید اصلاح شوند
|
|
# --- main_type
|
|
|
|
# # POST mj_qa_qanon/_update_by_query
|
|
# body = {
|
|
# "query": {"bool": {"must_not": [{"exists": {"field": "main_type"}}]}},
|
|
# "script": {
|
|
# "source": """
|
|
|
|
# ctx._source.main_type = 'قانون'
|
|
# """,
|
|
# "lang": "painless"
|
|
# }
|
|
# }
|
|
# elastic.updateByQueryIndex("mj_qa_qanon", body)
|
|
|
|
|
|
# # POST mj_qa_qanon/_update_by_query
|
|
# body = {
|
|
# "query": {"terms": {"main_type": ["اصلی", "تبعی"]}},
|
|
# "script": {
|
|
# "source": """
|
|
|
|
# ctx._source.sub_type = ctx._source.main_type;
|
|
# ctx._source.main_type = 'قانون'
|
|
# """,
|
|
# "lang": "painless"
|
|
# }
|
|
# }
|
|
# elastic.updateByQueryIndex("mj_qa_qanon", body)
|
|
|
|
# #----------------------------------------------
|
|
# #---- در مپ إعمال شد و نیاز نیست دیگه
|
|
# # PUT mj_df_qanon/_mapping
|
|
# # {
|
|
# # "properties":{
|
|
# # "mom_type": {
|
|
# # "type": "keyword"
|
|
# # },
|
|
# # "main_type_key": {
|
|
# # "type": "keyword"
|
|
# # }
|
|
# # }
|
|
# # }
|
|
# #----------------------------------------------
|
|
|
|
# # POST mj_df_qanon/_update_by_query
|
|
# body = {
|
|
# "query": {"terms": {"main_type": ["اصلی", "تبعی"]}},
|
|
# "script": {
|
|
# "source": """
|
|
|
|
# ctx._source.mom_type = ctx._source.main_type;
|
|
# ctx._source.main_type = 'قانون';
|
|
# ctx._source.main_type_key = 'qasection';
|
|
# """,
|
|
# "lang": "painless"
|
|
# }
|
|
# }
|
|
# elastic.updateByQueryIndex("mj_df_qanon", body)
|
|
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_df_qanon", "mj_df_qanon_1_date")
|
|
|
|
|
|
# --------------------------------------------- 3 ------------------------------------------------------------------
|
|
# --- درج داده های جدید مقررات و آراء در فهرست همه
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
|
|
# --- موقت
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_qanon", "mj_qa_qanon_1_date")
|
|
|
|
|
|
# -- حذف مقرره های قبلی
|
|
# body = {"query": {"term": {"main_type": {"value": "مقرره"}}}}
|
|
# elastic.deleteByQueryIndex("mj_qa_qanon", body)
|
|
|
|
# --- موقت
|
|
# 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/dotic_14040824/mj_qa_qanon_doctic_14040824.zip")
|
|
|
|
# -------------------------------------
|
|
# ----- انتقال داده های آراء به
|
|
#--- بخاطر لزوم تغییر روش کار، لازم شد محتوای آراء به اینجا منتفل شود
|
|
#--- البته بقیه فراداده قبلا منتقل شده بودند
|
|
|
|
file_path = 'G:/Project2/160_dotic/dotic_14040824/mj_qa_opinion_doctic_14040824.zip'
|
|
# import_content_opinion_to_qaqanon(elastic, file_path, "mj_qa_qanon" )
|
|
|
|
### ---موقت : یکبار
|
|
### بخاطر خطای داده در سرور مجلس
|
|
# extract_content_opinion_to_qaqanon(elastic, file_path, "mj_qa_qanon", 'G:/Project2/160_dotic/dotic_14040824/extract/' )
|
|
|
|
|
|
# # -------------------------------------
|
|
# # ----- انتقال داده های مشروح مذاکرات به فهرست همه قوانین
|
|
# ??????فعلا انجام نشده # file_path = 'G:/Project2/160_dotic/mj_mashruh.zip'
|
|
|
|
|
|
# --- موقت
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_qanon", "mj_qa_qanon_3_base_dotic")
|
|
|
|
# --------------------------------------------- 4 ------------------------------------------------------------------
|
|
# ---------------------------------------------------------------------------------------------------------------
|
|
file_before = "G:/Project2/160_dotic/duplicate_before.json"
|
|
file_after = "G:/Project2/160_dotic/duplicate_after.json"
|
|
file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
|
|
|
|
|
|
# # #------------------------------------------
|
|
# duplicate_list = {}
|
|
# file_excel = r"G:\Project2\dataParsers\data\qavanin_files\qavanin_output4.xlsx"
|
|
# import_excel_before_to_elastic(elastic, file_excel, "mj_qa_qanon", duplicate_list)
|
|
|
|
# with open(file_before, 'w', encoding='utf8') as f :
|
|
# json.dump(duplicate_list, f, ensure_ascii=False, indent=4)
|
|
|
|
|
|
# # # #------------------------------------------
|
|
# duplicate_list = {}
|
|
# with open(file_before, 'r', encoding='utf8') as f :
|
|
# duplicate_list = json.loads( f.read())
|
|
# file_excel = r"G:\Project2\dataParsers\data\qavanin_files\qavanin_output4.xlsx"
|
|
# import_excel_after_to_elastic(elastic, file_excel, "mj_qa_qanon", duplicate_list)
|
|
|
|
# with open(file_after, 'w', encoding='utf8') as f :
|
|
# json.dump(duplicate_list, f, ensure_ascii=False, indent=4)
|
|
|
|
|
|
# # # # #------------------------------------------
|
|
# duplicate_list = {}
|
|
# with open(file_after, 'r', encoding='utf8') as f :
|
|
# duplicate_list = json.loads( f.read())
|
|
# file_excel = r"G:\Project2\dataParsers\data\qavanin_files\فهرست تصمیمات قانونی.xlsx"
|
|
# import_excel_tasmimat_to_elastic(elastic, file_excel, "mj_qa_qanon", duplicate_list)
|
|
# with open(file_tasmim, 'w', encoding='utf8') as f :
|
|
# json.dump(duplicate_list, f, ensure_ascii=False, indent=4)
|
|
|
|
|
|
# # --- موقت
|
|
#elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_qanon", "mj_qa_qanon_4_base_excel")
|
|
|
|
|
|
#---------تنظیم شد mj_qa_qanon_new.json
|
|
# #----------------------------
|
|
# PUT mj_qa_qanon/_settings
|
|
# {
|
|
# "index" : {
|
|
# "max_result_window" : 200000
|
|
# }
|
|
# }
|
|
|
|
# .....
|
|
|
|
# --------------
|
|
# ---- تذکر فرانت و بک
|
|
# -- اصلاح ساختار اسکیما نماش و تغییرات برای ساختار تاریخ تغییر یافته و تست و بررسی
|
|
# .....
|
|
# .....
|
|
# ------------------------------------------------------------------------------------------------------------
|
|
# ------------------------------------------------------------------------------------------------------------
|
|
|
|
#------------------------------------
|
|
#--- mj_qa_section
|
|
|
|
#elastic.backupIndexToZipfile("G:/Project2/160_dotic/majles_14040926", "mj_qa_section", "mj_qa_section_1_base")
|
|
|
|
# بررسی پر بودن main_type مجلس برای نوع اصلی/تبعی/مهذب # و تغییر به mom_type
|
|
#### schema changed --> qasection_mom_type
|
|
|
|
|
|
# # POST mj_qa_section/_update_by_query
|
|
# body = {
|
|
# "query": {"terms": {"main_type": ["اصلی", "تبعی"]}},
|
|
# "script": {
|
|
# "source": """
|
|
|
|
# ctx._source.mom_type = ctx._source.main_type;
|
|
# ctx._source.main_type = 'قانون'
|
|
# """,
|
|
# "lang": "painless"
|
|
# }
|
|
# }
|
|
# 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.createIndex( 'mj_mashruh', 'majles', 'mj_mashruh', path_base_map+ 'majles/'+'mj_mashruh.json' )
|
|
# 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.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_qanon_base_excel.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon')
|
|
|
|
|
|
# elastic.createIndex( 'mj_qa_section', 'majles', 'mj_qa_section', path_base_map+ 'majles/'+'mj_qa_section.json' )
|
|
# 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.json' )
|
|
# 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/102_gpu", "mj_qa_semantic_section", "mj_qa_semantic_section")
|
|
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_section_rule", "mj_qa_section_rule")
|
|
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh")
|
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_section", "mj_qa_section")
|
|
|
|
|
|
|
|
|
|
|
|
### ---------------------------------------------------------------------
|
|
### ---- برای مرحله بعدی
|
|
### ---------------------------------------------------------------------
|
|
|
|
## این جزء ها خراب هستند و محتوا و اطلاعات واجب را ندارند ، لذا حذف شوند
|
|
error_section_ids = [
|
|
"qs236537_437131",
|
|
"qs236537_437121",
|
|
"qs236537_4371511",
|
|
"qs236537_437151",
|
|
"qs236537_4371531",
|
|
"qs236537_4371541",
|
|
"qs236537_437141",
|
|
"qs236537_4371521"
|
|
]
|
|
|
|
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_rule", "mj_qa_rule")
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_context", "mj_qa_context")
|
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_conflict", "mj_qa_conflict")
|