all_sql_steps , repair qa_qanon
This commit is contained in:
@@ -9,7 +9,8 @@ import pyodbc
|
|||||||
# TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDM4NTQ0MTEsImp0aSI6IjhDOWErR3BPMGk5U3Blc0ZFT251RDNoM2t3XC82R1BWTiIsImlzcyI6bnVsbCwiZXhwIjoxNzQ1MTU0NDEwLCJhdWQiOm51bGwsImRhdGEiOnsiaWQiOjEsImZpcnN0X25hbWUiOiJcdTA2NDVcdTA2MmZcdTA2Y2NcdTA2MzEgXHUwNjQxXHUwNjQ2XHUwNmNjIiwibGFzdF9uYW1lIjoiXHUwNjMzXHUwNjI3XHUwNjQ1XHUwNjI3XHUwNjQ2XHUwNjQ3IiwiZW1haWwiOiJkZXZAZ21haWwuY29tIiwidXNlcm5hbWUiOiJkZXYiLCJ1c2VyX2xldmVsIjoyfX0.jke3m7QD2pj7E18fBJYjiz9FrYbl6ZxVaYbLt9jfZu0'
|
# TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDM4NTQ0MTEsImp0aSI6IjhDOWErR3BPMGk5U3Blc0ZFT251RDNoM2t3XC82R1BWTiIsImlzcyI6bnVsbCwiZXhwIjoxNzQ1MTU0NDEwLCJhdWQiOm51bGwsImRhdGEiOnsiaWQiOjEsImZpcnN0X25hbWUiOiJcdTA2NDVcdTA2MmZcdTA2Y2NcdTA2MzEgXHUwNjQxXHUwNjQ2XHUwNmNjIiwibGFzdF9uYW1lIjoiXHUwNjMzXHUwNjI3XHUwNjQ1XHUwNjI3XHUwNjQ2XHUwNjQ3IiwiZW1haWwiOiJkZXZAZ21haWwuY29tIiwidXNlcm5hbWUiOiJkZXYiLCJ1c2VyX2xldmVsIjoyfX0.jke3m7QD2pj7E18fBJYjiz9FrYbl6ZxVaYbLt9jfZu0'
|
||||||
# TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDQ5MDExMzgsImp0aSI6IldsWnRWa0dxZTUwbHQwc1VRXC82TW1zeUFGcytTdXVwWSIsImlzcyI6bnVsbCwiZXhwIjoxNzQ2MjAxMTM3LCJhdWQiOm51bGwsImRhdGEiOnsiaWQiOjEsImZpcnN0X25hbWUiOiJcdTA2NDVcdTA2MmZcdTA2Y2NcdTA2MzEgXHUwNjQxXHUwNjQ2XHUwNmNjIiwibGFzdF9uYW1lIjoiXHUwNjMzXHUwNjI3XHUwNjQ1XHUwNjI3XHUwNjQ2XHUwNjQ3IiwiZW1haWwiOiJkZXZAZ21haWwuY29tIiwidXNlcm5hbWUiOiJkZXYiLCJ1c2VyX2xldmVsIjoyfX0.EXMgeLkudzt9_94SoYQm09ERf6ES2FIleXgMAPXkygk'
|
# TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDQ5MDExMzgsImp0aSI6IldsWnRWa0dxZTUwbHQwc1VRXC82TW1zeUFGcytTdXVwWSIsImlzcyI6bnVsbCwiZXhwIjoxNzQ2MjAxMTM3LCJhdWQiOm51bGwsImRhdGEiOnsiaWQiOjEsImZpcnN0X25hbWUiOiJcdTA2NDVcdTA2MmZcdTA2Y2NcdTA2MzEgXHUwNjQxXHUwNjQ2XHUwNmNjIiwibGFzdF9uYW1lIjoiXHUwNjMzXHUwNjI3XHUwNjQ1XHUwNjI3XHUwNjQ2XHUwNjQ3IiwiZW1haWwiOiJkZXZAZ21haWwuY29tIiwidXNlcm5hbWUiOiJkZXYiLCJ1c2VyX2xldmVsIjoyfX0.EXMgeLkudzt9_94SoYQm09ERf6ES2FIleXgMAPXkygk'
|
||||||
# TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDY2MDA0NjUsImp0aSI6Im9IRjJiRW81ZzhXZm9UdGdrb1BZWmpTb3Arem84N3llIiwiaXNzIjpudWxsLCJleHAiOjE3NDc5MDA0NjQsImF1ZCI6bnVsbCwiZGF0YSI6eyJpZCI6MiwiZmlyc3RfbmFtZSI6Ilx1MDYyZFx1MDY0NVx1MDZjY1x1MDYyZiIsImxhc3RfbmFtZSI6Ilx1MDYzNVx1MDY0MVx1MDYyN1x1MDZjY1x1MDZjYyIsImVtYWlsIjoic2FmYWVpLmhhbWlkQGdtYWlsLmNvbSIsInVzZXJuYW1lIjoiaHNhZmFlaSIsInVzZXJfbGV2ZWwiOjJ9fQ.rKb7fD7hnszRSK2720hvnTE28AFceBRWZIN1H1fC0sw'
|
# TOKEN = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDY2MDA0NjUsImp0aSI6Im9IRjJiRW81ZzhXZm9UdGdrb1BZWmpTb3Arem84N3llIiwiaXNzIjpudWxsLCJleHAiOjE3NDc5MDA0NjQsImF1ZCI6bnVsbCwiZGF0YSI6eyJpZCI6MiwiZmlyc3RfbmFtZSI6Ilx1MDYyZFx1MDY0NVx1MDZjY1x1MDYyZiIsImxhc3RfbmFtZSI6Ilx1MDYzNVx1MDY0MVx1MDYyN1x1MDZjY1x1MDZjYyIsImVtYWlsIjoic2FmYWVpLmhhbWlkQGdtYWlsLmNvbSIsInVzZXJuYW1lIjoiaHNhZmFlaSIsInVzZXJfbGV2ZWwiOjJ9fQ.rKb7fD7hnszRSK2720hvnTE28AFceBRWZIN1H1fC0sw'
|
||||||
TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDgyNTY3MTYsImp0aSI6IlZWejlWRDFGMUx5UkEyd01EaW5od3M3cTJRRkVqYW9kIiwiaXNzIjpudWxsLCJleHAiOjE3NDk1NTY3MTUsImF1ZCI6bnVsbCwiZGF0YSI6eyJpZCI6MSwiZmlyc3RfbmFtZSI6Ilx1MDY0NVx1MDYyZlx1MDZjY1x1MDYzMSBcdTA2NDFcdTA2NDZcdTA2Y2MiLCJsYXN0X25hbWUiOiJcdTA2MzNcdTA2MjdcdTA2NDVcdTA2MjdcdTA2NDZcdTA2NDciLCJlbWFpbCI6ImRldkBnbWFpbC5jb20iLCJ1c2VybmFtZSI6ImRldiIsInVzZXJfbGV2ZWwiOjJ9fQ.QljFs4f0HFT7S8qrib6q54kMWg7z381v2uqoiSFDfR4'
|
# TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDgyNTY3MTYsImp0aSI6IlZWejlWRDFGMUx5UkEyd01EaW5od3M3cTJRRkVqYW9kIiwiaXNzIjpudWxsLCJleHAiOjE3NDk1NTY3MTUsImF1ZCI6bnVsbCwiZGF0YSI6eyJpZCI6MSwiZmlyc3RfbmFtZSI6Ilx1MDY0NVx1MDYyZlx1MDZjY1x1MDYzMSBcdTA2NDFcdTA2NDZcdTA2Y2MiLCJsYXN0X25hbWUiOiJcdTA2MzNcdTA2MjdcdTA2NDVcdTA2MjdcdTA2NDZcdTA2NDciLCJlbWFpbCI6ImRldkBnbWFpbC5jb20iLCJ1c2VybmFtZSI6ImRldiIsInVzZXJfbGV2ZWwiOjJ9fQ.QljFs4f0HFT7S8qrib6q54kMWg7z381v2uqoiSFDfR4'
|
||||||
|
TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NjM0NjM1NDcsImp0aSI6Ik02RmN3VkhlZTJLbTlmZ2ZPbk9pdHgrYVpMc2xoclhrIiwiaXNzIjpudWxsLCJleHAiOjE3NjQ3NjM1NDYsImF1ZCI6bnVsbCwiZGF0YSI6eyJpZCI6MSwiZmlyc3RfbmFtZSI6Ilx1MDY0NVx1MDYyZlx1MDZjY1x1MDYzMSBcdTA2NDFcdTA2NDZcdTA2Y2MiLCJsYXN0X25hbWUiOiJcdTA2MzNcdTA2MjdcdTA2NDVcdTA2MjdcdTA2NDZcdTA2NDciLCJlbWFpbCI6ImRldkBnbWFpbC5jb20iLCJ1c2VybmFtZSI6ImRldiIsInVzZXJfbGV2ZWwiOjJ9fQ.f-J12LHU6a166w0RlMJX4c2uhWwbe_usfeKHpcgZzg8'
|
||||||
ACCEPT = "application/json"
|
ACCEPT = "application/json"
|
||||||
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
|
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
|
||||||
|
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ class ElasticHelper:
|
|||||||
path_back,
|
path_back,
|
||||||
index_name,
|
index_name,
|
||||||
file_name="",
|
file_name="",
|
||||||
body={"size": 1000},
|
body={},
|
||||||
byzip=True,
|
byzip=True,
|
||||||
fields=[],
|
fields=[],
|
||||||
noFields=[],
|
noFields=[],
|
||||||
@@ -270,6 +270,8 @@ class ElasticHelper:
|
|||||||
if body == {}:
|
if body == {}:
|
||||||
s_res = self.es.search(index=index_name, scroll="5m", size=1000)
|
s_res = self.es.search(index=index_name, scroll="5m", size=1000)
|
||||||
else:
|
else:
|
||||||
|
if not "size" in body :
|
||||||
|
body["size"] = 1000
|
||||||
s_res = self.es.search(index=index_name, scroll="5m", body=body)
|
s_res = self.es.search(index=index_name, scroll="5m", body=body)
|
||||||
self.total = s_res["hits"]["total"]["value"]
|
self.total = s_res["hits"]["total"]["value"]
|
||||||
if self.total == 0:
|
if self.total == 0:
|
||||||
@@ -651,7 +653,7 @@ class ElasticHelper:
|
|||||||
# - دادهها را به صورت bulk وارد میکند
|
# - دادهها را به صورت bulk وارد میکند
|
||||||
# - از helpers.bulk Elasticsearch استفاده میکند
|
# - از helpers.bulk Elasticsearch استفاده میکند
|
||||||
# -----------------------------end----------------------------
|
# -----------------------------end----------------------------
|
||||||
def importJsonDataToElastic(self, jsonData, index_name, fields=[]):
|
def importJsonDataToElastic(self, jsonData, index_name, fields=[], streem_state = False):
|
||||||
chunk_size = 100000
|
chunk_size = 100000
|
||||||
raise_on_error = False
|
raise_on_error = False
|
||||||
raise_on_exception = False
|
raise_on_exception = False
|
||||||
@@ -677,7 +679,19 @@ class ElasticHelper:
|
|||||||
"_source": source,
|
"_source": source,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
helpers.bulk(
|
if streem_state :
|
||||||
|
### /// برای مواردی که نیاز هست خطا فهمیده شود
|
||||||
|
for ok, result in helpers.streaming_bulk(
|
||||||
|
self.es,
|
||||||
|
actions,
|
||||||
|
raise_on_error=False,
|
||||||
|
raise_on_exception=False,
|
||||||
|
):
|
||||||
|
if not ok:
|
||||||
|
print("Error:", result)
|
||||||
|
|
||||||
|
else :
|
||||||
|
success, errors = helpers.bulk(
|
||||||
self.es,
|
self.es,
|
||||||
actions,
|
actions,
|
||||||
chunk_size,
|
chunk_size,
|
||||||
@@ -686,6 +700,8 @@ class ElasticHelper:
|
|||||||
stats_only,
|
stats_only,
|
||||||
yield_ok,
|
yield_ok,
|
||||||
)
|
)
|
||||||
|
return success, errors
|
||||||
|
|
||||||
|
|
||||||
# ----------------------------start---------------------------
|
# ----------------------------start---------------------------
|
||||||
# متد fileToElastic:
|
# متد fileToElastic:
|
||||||
@@ -758,7 +774,7 @@ class ElasticHelper:
|
|||||||
print("index:", index_name, "=>", filename)
|
print("index:", index_name, "=>", filename)
|
||||||
with zObject.open(filename) as file:
|
with zObject.open(filename) as file:
|
||||||
data = json.loads(file.read())
|
data = json.loads(file.read())
|
||||||
self.importJsonDataToElastic(data, index_name, fields)
|
result = self.importJsonDataToElastic(data, index_name, fields)
|
||||||
|
|
||||||
self.es.indices.refresh(index=index_name)
|
self.es.indices.refresh(index=index_name)
|
||||||
print(self.es.cat.count(index=index_name, format="json"))
|
print(self.es.cat.count(index=index_name, format="json"))
|
||||||
|
|||||||
@@ -402,15 +402,25 @@ def jdate2timestamp_old(dt):
|
|||||||
return tst
|
return tst
|
||||||
|
|
||||||
def jdate2timestamp(dt):
|
def jdate2timestamp(dt):
|
||||||
ndt = dt.replace("y", "")
|
text = dt
|
||||||
ndt = ndt.replace("m", "/")
|
if dt.startswith("y") :
|
||||||
ndt = ndt.replace("d", "/")
|
# y1404m1d14
|
||||||
gd = Persian(ndt).gregorian_datetime()
|
text = dt.replace("y", "")
|
||||||
|
text = text.replace("m", "/")
|
||||||
|
text = text.replace("d", "/")
|
||||||
|
|
||||||
|
gd = Persian(text).gregorian_datetime()
|
||||||
base = datetime.date(1970, 1, 1)
|
base = datetime.date(1970, 1, 1)
|
||||||
rr = (gd-base).total_seconds()
|
rr = (gd-base).total_seconds()
|
||||||
tst = int( round(rr) * 1000)
|
tst = int( round(rr) * 1000)
|
||||||
return tst
|
return tst
|
||||||
|
|
||||||
|
def jdate2Gregorian(text):
|
||||||
|
gd = Persian(text).gregorian_datetime()
|
||||||
|
tst = gd.strftime("%Y-%m-%d")
|
||||||
|
# tst = d.isoformat()
|
||||||
|
return tst
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def getSortTimestamp(ts_date):
|
def getSortTimestamp(ts_date):
|
||||||
@@ -1123,6 +1133,45 @@ def myTimestamp(days=0):
|
|||||||
|
|
||||||
#////////////////////////////////////////////////////////////
|
#////////////////////////////////////////////////////////////
|
||||||
#////////////////////////////////////////////////////////////
|
#////////////////////////////////////////////////////////////
|
||||||
|
def is_match_persian_date_format(text):
|
||||||
|
if text == '0000/00/00' :
|
||||||
|
return False
|
||||||
|
|
||||||
|
if text == '00/00/00' :
|
||||||
|
return False
|
||||||
|
|
||||||
|
# items = text.split('/')
|
||||||
|
|
||||||
|
pattern = r'\d{4}/\d{1,2}/\d{1,2}'
|
||||||
|
if re.match(pattern,text) :
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def excel_to_json(excel_file, required_columns=None, sheet_name=0):
|
||||||
|
"""
|
||||||
|
خواندن یک sheet از فایل اکسل و تبدیل به لیست دیکشنری.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
sheet_name: نام sheet (رشته) یا شماره آن (عدد). پیشفرض: 0 (اولین sheet)
|
||||||
|
"""
|
||||||
|
sheet_names = pd.ExcelFile(excel_file).sheet_names
|
||||||
|
|
||||||
|
print("all sheet")
|
||||||
|
for i, name in enumerate(sheet_names, start=1):
|
||||||
|
print(f" {i}. {name}")
|
||||||
|
|
||||||
|
df = pd.read_excel(excel_file, sheet_name=sheet_name)
|
||||||
|
|
||||||
|
if required_columns is None:
|
||||||
|
selected_columns = df.columns.tolist()
|
||||||
|
else:
|
||||||
|
missing = [col for col in required_columns if col not in df.columns]
|
||||||
|
if missing:
|
||||||
|
raise ValueError(f"ستونهای مفقوده در sheet '{sheet_name}': {missing}")
|
||||||
|
selected_columns = required_columns
|
||||||
|
|
||||||
|
return df[selected_columns].to_dict(orient="records")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -557,32 +557,43 @@ def extract_codes_to_json( file_excel, tcode_label, file_json):
|
|||||||
df = pd.read_excel(file_excel, sheet_name=0)
|
df = pd.read_excel(file_excel, sheet_name=0)
|
||||||
count = 0
|
count = 0
|
||||||
rows_list = df.to_dict(orient='records')
|
rows_list = df.to_dict(orient='records')
|
||||||
total = len(df[0])
|
|
||||||
print('total : ', total)
|
|
||||||
|
|
||||||
column_names = df.columns.tolist()
|
column_names = df.columns.tolist()
|
||||||
print(column_names)
|
print(column_names)
|
||||||
|
|
||||||
|
number_base = 0
|
||||||
|
total = len(df)
|
||||||
|
|
||||||
|
print('total : ', total)
|
||||||
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
total_update=0
|
total_update=0
|
||||||
row_number = 0
|
row_number = 0
|
||||||
try:
|
try:
|
||||||
for row in rows_list:
|
for row in rows_list:
|
||||||
|
|
||||||
section_title = row[column_names[0]]
|
section_title = ""
|
||||||
|
section_id = ""
|
||||||
|
try:
|
||||||
|
section_title = row[column_names[number_base]]
|
||||||
# ts_date = row[column_names[1]]
|
# ts_date = row[column_names[1]]
|
||||||
# qanon_title = row[column_names[2]]
|
# qanon_title = row[column_names[2]]
|
||||||
code_state = row[column_names[3]]
|
code_state = row[column_names[number_base+3]]
|
||||||
row_number = row[column_names[4]]
|
row_number = row[column_names[number_base+4]]
|
||||||
# qanon_id = row[column_names[5]]
|
# qanon_id = row[column_names[5]]
|
||||||
section_id = row[column_names[6]]
|
section_id = row[column_names[number_base+6]]
|
||||||
# state_match = row[column_names[7]]
|
# state_match = row[column_names[7]]
|
||||||
|
except :
|
||||||
|
pass
|
||||||
|
|
||||||
section_id_new = 0
|
section_id_new = 0
|
||||||
# c_name = 'حکم' # بعضی فایلهای اصلاحی، شناسه اینجا ذخیره شده بود
|
# c_name = 'حکم' # بعضی فایلهای اصلاحی، شناسه اینجا ذخیره شده بود
|
||||||
# if c_name in column_names :
|
# if c_name in column_names :
|
||||||
# section_id_new = row[c_name]
|
# section_id_new = row[c_name]
|
||||||
|
|
||||||
|
if is_nan_or_none_or_empty(section_title) :
|
||||||
|
continue
|
||||||
|
|
||||||
if not is_nan_or_none_or_empty(section_id_new) and section_id_new != 0 :
|
if not is_nan_or_none_or_empty(section_id_new) and section_id_new != 0 :
|
||||||
section_id = section_id_new
|
section_id = section_id_new
|
||||||
|
|
||||||
@@ -625,7 +636,7 @@ def run_codes_to_elastic_directory(elastic, directory, output, all_codes, update
|
|||||||
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]
|
code_name = _name.split('_')[0]
|
||||||
print('=========================== start code_name ===> ', code_name)
|
print('=========================== start code_name ===> ', code_name[::-1])
|
||||||
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"
|
||||||
file_path = os.path.join(directory, file)
|
file_path = os.path.join(directory, file)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from collections import defaultdict
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from app.common.text_normalizer import TextNormalizer
|
from app.common.text_normalizer import TextNormalizer
|
||||||
from app.common.elastic_helper import ElasticHelper
|
from app.common.elastic_helper import ElasticHelper
|
||||||
|
from app.common.general_functions import excel_to_json
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
@@ -31,32 +32,6 @@ from openpyxl import Workbook
|
|||||||
text_normalizer = TextNormalizer()
|
text_normalizer = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
def excel_to_json(excel_file, required_columns=None, sheet_name=0):
|
|
||||||
"""
|
|
||||||
خواندن یک sheet از فایل اکسل و تبدیل به لیست دیکشنری.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
sheet_name: نام sheet (رشته) یا شماره آن (عدد). پیشفرض: 0 (اولین sheet)
|
|
||||||
"""
|
|
||||||
sheet_names = pd.ExcelFile(excel_file).sheet_names
|
|
||||||
|
|
||||||
print("all sheet")
|
|
||||||
for i, name in enumerate(sheet_names, start=1):
|
|
||||||
print(f" {i}. {name}")
|
|
||||||
|
|
||||||
df = pd.read_excel(excel_file, sheet_name=sheet_name)
|
|
||||||
|
|
||||||
if required_columns is None:
|
|
||||||
selected_columns = df.columns.tolist()
|
|
||||||
else:
|
|
||||||
missing = [col for col in required_columns if col not in df.columns]
|
|
||||||
if missing:
|
|
||||||
raise ValueError(f"ستونهای مفقوده در sheet '{sheet_name}': {missing}")
|
|
||||||
selected_columns = required_columns
|
|
||||||
|
|
||||||
return df[selected_columns].to_dict(orient="records")
|
|
||||||
|
|
||||||
|
|
||||||
def update_history_code(elastic, data, index_name_o, sub_key, label_name, version_key):
|
def update_history_code(elastic, data, index_name_o, sub_key, label_name, version_key):
|
||||||
|
|
||||||
send_round = 1
|
send_round = 1
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
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
|
||||||
|
from app.parvande_qanon.import_qavanin_files_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')
|
||||||
|
# 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)
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
#--- مواردی از قانونهای جدید که فیلد زیر را ندارند باید اصلاح شوند
|
||||||
|
#--- 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)
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
#------ استخراج برخی کدهای باقیمانده که اکسل آنها از قبل موجود هست و تولید فایل مناسب برای درج فایل محور در بانک مجلس
|
||||||
|
#---
|
||||||
|
all_codes = []
|
||||||
|
with open("./data/codes49.json", "r", encoding="utf8") as f:
|
||||||
|
codes_1 = json.load(f)
|
||||||
|
all_codes = codes_1
|
||||||
|
|
||||||
|
# run_codes_extract_directory( "./data/tcodes/corrected_majles/not_edit2", "./data/tcodes/corrected_majles/not_edit2/result_json", all_codes)
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
#----- پشتیبان گیری از داده های جدید داتیک
|
||||||
|
|
||||||
|
# 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")
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
#----- ترمیم داده های تاریخ ایندکس قبلی
|
||||||
|
# -- qaqanon
|
||||||
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_qanon")
|
||||||
|
|
||||||
|
# file_path = 'G:/Project2/111/mj_qa_qanon.zip'
|
||||||
|
file_path = 'G:/Project2/160_dotic/mj_qa_qanon_112.zip'
|
||||||
|
index_name = "mj_qa_qanon"
|
||||||
|
|
||||||
|
elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon')
|
||||||
|
# restore_correct_data_to_elastic(elastic, file_path, index_name )
|
||||||
|
elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_qanon_112.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon')
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
#-------------------------------------
|
||||||
|
|
||||||
|
#-- حذف مقرره های قبلی
|
||||||
|
body = {
|
||||||
|
"query": {
|
||||||
|
"term": {
|
||||||
|
"main_type": {
|
||||||
|
"value": "مقرره"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# elastic.deleteByQueryIndex("mj_qa_qanon", body)
|
||||||
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon_base")
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
#----- موقتی برای تستهای از این مرحله به بعد یه پشتیبان تمیز باشه ...
|
||||||
|
# elastic.createIndex( 'mj_qa_qanon', 'majles', 'mj_qa_qanon')
|
||||||
|
# elastic.restorFileToElastic2('G:/Project2/160_dotic/mj_qa_qanon_base.zip', 'mj_qa_qanon', 'majles', False, 'mj_qa_qanon')
|
||||||
|
|
||||||
|
|
||||||
|
# import_data_new_qaqanon(elastic, "G:/Project2/160_dotic/mj_qa_qanon_doctic_14040824.zip")
|
||||||
|
|
||||||
|
#-------------------------------------
|
||||||
|
#-------------------------------------
|
||||||
|
#-------------------------------------
|
||||||
|
|
||||||
|
# file_excel = "G:\Project2\NLP\dataParsers\data\qavanin_files\qavanin_output4.xlsx"
|
||||||
|
# import_excel_before_to_elastic(elastic, file_excel, "mj_qa_qanon")
|
||||||
|
|
||||||
|
|
||||||
|
# file_excel = "G:\Project2\NLP\dataParsers\data\qavanin_files\qavanin_output4.xlsx"
|
||||||
|
# import_excel_after_to_elastic(elastic, file_excel, "mj_qa_qanon")
|
||||||
|
|
||||||
|
|
||||||
|
# file_excel = "G:\Project2\NLP\dataParsers\data\qavanin_files\فهرست تصمیمات قانونی.elsx"
|
||||||
|
# import_excel_tasmimat_to_elastic(elastic, file_excel, "mj_qa_qanon")
|
||||||
@@ -1,6 +1,13 @@
|
|||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
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.config_base import *
|
from app.common.config_base import *
|
||||||
from app.common.general_functions import *
|
from app.common.general_functions import *
|
||||||
@@ -15,8 +22,28 @@ from s8_Relations_qanon_LWReg import *
|
|||||||
from s9_Relations_qanon_opinion import *
|
from s9_Relations_qanon_opinion import *
|
||||||
from s10_LawReg_lwphase_Info import *
|
from s10_LawReg_lwphase_Info import *
|
||||||
from s11_Tanghih_plan_move import *
|
from s11_Tanghih_plan_move import *
|
||||||
|
from s12_LawSection_repair_ref_state import *
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
load_dotenv(dotenv_path='config.env')
|
||||||
|
|
||||||
|
host=os.getenv('HOST_160')
|
||||||
|
password=os.getenv('HOST_160_PASS')
|
||||||
|
|
||||||
|
# host=os.getenv('HOST_112')
|
||||||
|
# password=os.getenv('HOST_112_PASS')
|
||||||
|
|
||||||
|
# host=os.getenv('HOST_113')
|
||||||
|
# password=os.getenv('HOST_113_PASS')
|
||||||
|
|
||||||
|
# print(password)
|
||||||
|
|
||||||
|
path_base_map = "G:/Project2/gateway_php/repo/_other/"
|
||||||
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||||
|
|
||||||
|
|
||||||
|
# 1
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
## ابتدا دستورات زیر را به ترتیب در دیتابیس فهرست اجرا شود
|
## ابتدا دستورات زیر را به ترتیب در دیتابیس فهرست اجرا شود
|
||||||
# SELECT id from tl_projects where title='موضوعات درختی قانون'
|
# SELECT id from tl_projects where title='موضوعات درختی قانون'
|
||||||
@@ -29,47 +56,80 @@ from s11_Tanghih_plan_move import *
|
|||||||
# DELETE mj_qa_opinion_temp
|
# DELETE mj_qa_opinion_temp
|
||||||
# -----------------------------------------------------------------
|
# -----------------------------------------------------------------
|
||||||
|
|
||||||
# cursor, cnxn = create_cursor()
|
with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
file.write('='* 60 + '\n')
|
||||||
|
file.write('='* 60 + '\n')
|
||||||
|
file.write('='* 60 + '\n')
|
||||||
|
file.write('==========> start : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
|
cursor, cnxn = create_cursor()
|
||||||
|
|
||||||
## ایجاد فهرست موضوعات قانون
|
## ایجاد فهرست موضوعات قانون
|
||||||
#projectid = insertProejct()
|
# projectid = insertProejct()
|
||||||
#insertProjectItems(cursor, projectid)
|
# insertProjectItems(cursor, projectid)
|
||||||
|
|
||||||
# 2
|
# 2
|
||||||
#import_law_section_to_elastic(cursor)
|
# elastic.createIndex( index_name='mj_qa_section_temp', app_key='majles', map_name='mj_qa_section')
|
||||||
|
# import_law_section_to_elastic(cursor, elastic, "mj_qa_section_temp")
|
||||||
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_law_section_to_elastic : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
|
|
||||||
# import_regulation_section_to_elastic(cursor)
|
# elastic.createIndex( index_name='mj_rg_section_temp', app_key='majles', map_name='mj_qa_section')
|
||||||
|
# import_regulation_section_to_elastic(cursor, elastic, "mj_rg_section_temp")
|
||||||
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_regulation_section_to_elastic : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
# import_opinion_to_elastic(cursor)
|
# # elastic.createIndex( index_name='mj_qa_opinion_temp', app_key='majles', map_name='mj_qa_opinion')
|
||||||
|
# # import_opinion_to_elastic(cursor, elastic, "mj_qa_opinion_temp")
|
||||||
|
#with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_opinion_to_elastic : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
### از ابتدا تا اینجا حدودا 24 ساعت کشید
|
# ### از ابتدا تا اینجا حدودا 24 ساعت کشید
|
||||||
|
|
||||||
|
# import_law_section_update_ref_state(cursor, elastic, "mj_qa_section_temp")
|
||||||
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_law_section_update_ref_state : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
|
|
||||||
# import_law_section_update_ref_state(cursor)
|
# import_regulation_section_update_ref_state(cursor, elastic, "mj_rg_section_temp")
|
||||||
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_regulation_section_update_ref_state : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
|
|
||||||
# import_regulation_section_update_ref_state(cursor)
|
# elastic.createIndex( index_name='mj_qa_qanon_temp', app_key='majles', map_name='mj_qa_qanon')
|
||||||
|
# import_law_reg_qanon_to_elastic(cursor, elastic, "mj_qa_qanon_temp")
|
||||||
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_law_reg_qanon_to_elastic : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
|
# # # # ## تا اینجا رسید و خطا داد
|
||||||
|
# import_relations_qanon_lwreg(cursor, elastic, "mj_qa_qanon_temp")
|
||||||
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_relations_qanon_lwreg : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
# import_law_reg_qanon_to_elastic(cursor)
|
# # # # ## اینجا خطا داد
|
||||||
|
# import_relations_qanon_opinion(cursor, elastic, "mj_qa_qanon_temp")
|
||||||
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_relations_qanon_opinion : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
# ## تا اینجا رسید و خطا داد
|
import_lawreg_lwphase_info(cursor, elastic, "mj_qa_qanon_temp")
|
||||||
# import_relations_qanon_lwreg(cursor)
|
with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
file.write('==========> finish import_lawreg_lwphase_info : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
# ## اینجا خطا داد
|
# import_law_section_repair_ref_state(cursor, elastic, "mj_qa_section_temp", "./output/log_s12.txt")
|
||||||
# import_relations_qanon_opinion(cursor)
|
# with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
# file.write('==========> finish import_law_section_repair_ref_state : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
# import_lawreg_lwphase_info(cursor)
|
|
||||||
|
|
||||||
# cursor.close()
|
|
||||||
# cnxn.close()
|
|
||||||
|
|
||||||
|
|
||||||
cursor, cnxn = create_cursor('db4minaei')
|
|
||||||
# #####import_tangih_tree_to_list(cursor)
|
|
||||||
import_tanghih_plan_codes(cursor)
|
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
cnxn.close()
|
cnxn.close()
|
||||||
|
|
||||||
|
with open("./data/log_all_sql_steps.txt", 'a+', encoding='utf8') as file :
|
||||||
|
file.write('==========> finish full : ' + str(datetime.datetime.now()) + '\n')
|
||||||
|
|
||||||
|
# cursor, cnxn = create_cursor('db4minaei')
|
||||||
|
#### دیگر نیازی نیست و استفاده ندارد
|
||||||
|
# #####import_tangih_tree_to_list(cursor)
|
||||||
|
# import_tanghih_plan_codes(cursor)
|
||||||
|
|
||||||
|
# cursor.close()
|
||||||
|
# cnxn.close()
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ from app.common.config_base import *
|
|||||||
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
|
||||||
|
|
||||||
def import_lawreg_lwphase_info(cursor):
|
def import_lawreg_lwphase_info(cursor, elastic, index_name_o) :
|
||||||
|
|
||||||
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
query='SELECT ID,CAPTION FROM [Qavanin].[dbo].[cmOrganization]'
|
query='SELECT ID,CAPTION FROM [Qavanin].[dbo].[cmOrganization]'
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
|
|
||||||
@@ -48,10 +51,9 @@ def import_lawreg_lwphase_info(cursor):
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
text_normal = TextNormalizer()
|
|
||||||
|
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
# url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
|
|
||||||
@@ -173,41 +175,24 @@ def import_lawreg_lwphase_info(cursor):
|
|||||||
if len(bulk_data) >= 100:
|
if len(bulk_data) >= 100:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' lawreg_lwphase_info , total='+str(total_count) , str(i)+ ', id=' + eid )
|
print('=' * 10, ' lawreg_lwphase_info , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(bulk_data)
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
|
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
# print(bulk_count)
|
# print(bulk_count)
|
||||||
if len(bulk_data) > 0:
|
if len(bulk_data) > 0:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' lawreg_lwphase_info , total='+str(total_count) )
|
print('=' * 10, ' lawreg_lwphase_info , total='+str(total_count) )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(bulk_data)
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
|
|
||||||
# print(response.text )
|
# print(response.text )
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -179,29 +179,3 @@ def import_law_section_repair_ref_state(cursor, elastic, index_name_o, file_log)
|
|||||||
print('end success import_law_section_update_ref_state')
|
print('end success import_law_section_update_ref_state')
|
||||||
t2= datetime.datetime.now()
|
t2= datetime.datetime.now()
|
||||||
print(t2-t1)
|
print(t2-t1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cursor, cnxn = create_cursor()
|
|
||||||
|
|
||||||
load_dotenv(dotenv_path='config.env')
|
|
||||||
|
|
||||||
host=os.getenv('HOST_160')
|
|
||||||
password=os.getenv('HOST_160_PASS')
|
|
||||||
|
|
||||||
# host=os.getenv('HOST_112')
|
|
||||||
# password=os.getenv('HOST_112_PASS')
|
|
||||||
|
|
||||||
# host=os.getenv('HOST_113')
|
|
||||||
# password=os.getenv('HOST_113_PASS')
|
|
||||||
|
|
||||||
# print(password)
|
|
||||||
|
|
||||||
path_base_map = "G:/Project2/gateway_php/repo/_other/"
|
|
||||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
|
||||||
|
|
||||||
|
|
||||||
import_law_section_repair_ref_state(cursor, elastic, "mj_qa_section", "./output/log_s12.txt")
|
|
||||||
|
|
||||||
cursor.close()
|
|
||||||
cnxn.close()
|
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ def insert(rows, projectid, IDS_DICT, childs ):
|
|||||||
"parent": parent,
|
"parent": parent,
|
||||||
}
|
}
|
||||||
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||||
|
|
||||||
New_ID = json.loads(result.text)["data"][0]["id"]
|
New_ID = json.loads(result.text)["data"][0]["id"]
|
||||||
print(str(row["ID"]) + '=' + str(New_ID))
|
print(str(row["ID"]) + '=' + str(New_ID))
|
||||||
IDS_DICT[str(row["ID"])] = {"id" : int(New_ID), 'title': row["CAPTION"]}
|
IDS_DICT[str(row["ID"])] = {"id" : int(New_ID), 'title': row["CAPTION"]}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from app.common.text_normalizer import TextNormalizer
|
|||||||
|
|
||||||
# cursor, cnxn = create_cursor()
|
# cursor, cnxn = create_cursor()
|
||||||
|
|
||||||
def import_law_section_to_elastic(cursor) :
|
def import_law_section_to_elastic(cursor, elastic, index_name_o) :
|
||||||
|
|
||||||
query = '''
|
query = '''
|
||||||
select
|
select
|
||||||
@@ -87,7 +87,7 @@ def import_law_section_to_elastic(cursor) :
|
|||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/section/multi/add"
|
# url = BASE_URL + "repo/majles/section/multi/add"
|
||||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
@@ -126,6 +126,8 @@ def import_law_section_to_elastic(cursor) :
|
|||||||
|
|
||||||
qanon_title = text_normal.normalize_qanon( row.lawTitle )
|
qanon_title = text_normal.normalize_qanon( row.lawTitle )
|
||||||
title_type = getTitleType(qanon_title)
|
title_type = getTitleType(qanon_title)
|
||||||
|
if(row.ISCORRECTIONLETTER == 1):
|
||||||
|
title_type = 'نامه'
|
||||||
|
|
||||||
eid='qs'+ str(row.sectionId)
|
eid='qs'+ str(row.sectionId)
|
||||||
|
|
||||||
@@ -147,9 +149,7 @@ def import_law_section_to_elastic(cursor) :
|
|||||||
sub_type = row.regulationType
|
sub_type = row.regulationType
|
||||||
sub_type = normalYehKe(sub_type)
|
sub_type = normalYehKe(sub_type)
|
||||||
|
|
||||||
# other_type = 'اصلی'
|
|
||||||
# if(row.ISCORRECTIONLETTER == 1):
|
|
||||||
# other_type = 'اصلاحی'
|
|
||||||
|
|
||||||
|
|
||||||
ts_year = ''
|
ts_year = ''
|
||||||
@@ -238,39 +238,28 @@ def import_law_section_to_elastic(cursor) :
|
|||||||
|
|
||||||
if len(bulk_data) >= 200:
|
if len(bulk_data) >= 200:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId , ', lawid_first=' + bulk_data[0]['qanon_id'])
|
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
|
|
||||||
bulk_data.append(data)
|
|
||||||
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if len(bulk_data) > 0:
|
if len(bulk_data) > 0:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId , ', lawid_first=' + bulk_data[0]['qanon_id'])
|
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
bulk_data = []
|
||||||
|
|
||||||
|
|
||||||
print('end success import_law_section_to_elastic')
|
print('end success import_law_section_to_elastic')
|
||||||
t2= datetime.datetime.now()
|
t2= datetime.datetime.now()
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from app.common.config_base import *
|
|||||||
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
|
||||||
|
|
||||||
def import_opinion_to_elastic(cursor) :
|
def import_opinion_to_elastic(cursor, elastic, index_name_o) :
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
isnull(o.[ID],0) as ref_id
|
isnull(o.[ID],0) as ref_id
|
||||||
@@ -41,7 +41,7 @@ def import_opinion_to_elastic(cursor) :
|
|||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/opinion/multi/add" # POST /repo/majles/opinion/multi/add
|
# url = BASE_URL + "repo/majles/opinion/multi/add" # POST /repo/majles/opinion/multi/add
|
||||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
@@ -163,36 +163,26 @@ def import_opinion_to_elastic(cursor) :
|
|||||||
if len(bulk_data) >= 100:
|
if len(bulk_data) >= 100:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, 'opinion_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
print('=' * 10, 'opinion_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
|
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if len(bulk_data) > 0:
|
if len(bulk_data) > 0:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' opinion_to_elastic , total='+str(total_count) )
|
print('=' * 10, ' opinion_to_elastic , total='+str(total_count) )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
bulk_data = []
|
||||||
|
|
||||||
print("end success import_opinion_to_elastic")
|
print("end success import_opinion_to_elastic")
|
||||||
t2 = datetime.datetime.now()
|
t2 = datetime.datetime.now()
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from app.common.config_base import *
|
|||||||
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
|
||||||
|
|
||||||
def import_regulation_section_to_elastic(cursor):
|
def import_regulation_section_to_elastic(cursor, elastic, index_name_o):
|
||||||
query = '''
|
query = '''
|
||||||
select
|
select
|
||||||
s.ID as sectionId
|
s.ID as sectionId
|
||||||
@@ -87,7 +87,7 @@ def import_regulation_section_to_elastic(cursor):
|
|||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/rgsection/multi/add"
|
# url = BASE_URL + "repo/majles/rgsection/multi/add"
|
||||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
@@ -125,6 +125,8 @@ def import_regulation_section_to_elastic(cursor):
|
|||||||
|
|
||||||
qanon_title = text_normal.normalize_qanon( row.lawTitle )
|
qanon_title = text_normal.normalize_qanon( row.lawTitle )
|
||||||
title_type = getTitleType(qanon_title)
|
title_type = getTitleType(qanon_title)
|
||||||
|
if(row.ISCORRECTIONLETTER == 1):
|
||||||
|
title_type = 'نامه'
|
||||||
|
|
||||||
eid='qs'+ str(row.sectionId)
|
eid='qs'+ str(row.sectionId)
|
||||||
|
|
||||||
@@ -146,11 +148,6 @@ def import_regulation_section_to_elastic(cursor):
|
|||||||
sub_type = row.regulationType
|
sub_type = row.regulationType
|
||||||
sub_type = normalYehKe(sub_type)
|
sub_type = normalYehKe(sub_type)
|
||||||
|
|
||||||
# other_type = 'اصلی'
|
|
||||||
# if(row.ISCORRECTIONLETTER == 1):
|
|
||||||
# other_type = 'اصلاحی'
|
|
||||||
|
|
||||||
|
|
||||||
ts_year = ''
|
ts_year = ''
|
||||||
if row.aproveDate :
|
if row.aproveDate :
|
||||||
items = row.aproveDate.split("/")
|
items = row.aproveDate.split("/")
|
||||||
@@ -235,39 +232,22 @@ def import_regulation_section_to_elastic(cursor):
|
|||||||
|
|
||||||
if len(bulk_data) >= 200:
|
if len(bulk_data) >= 200:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' regulation_section , total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId , ', lawid_first=' + bulk_data[0]['qanon_id'])
|
print('=' * 10, ' regulation_section , total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId)
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
|
||||||
# print(response.text)
|
|
||||||
# print(row.txt)
|
|
||||||
|
|
||||||
bulk_data.append(data)
|
|
||||||
|
|
||||||
|
|
||||||
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if len(bulk_data) > 0:
|
if len(bulk_data) > 0:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' regulation_section , total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId , ', lawid_first=' + bulk_data[0]['qanon_id'])
|
print('=' * 10, ' regulation_section , total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
bulk_data = []
|
||||||
|
|
||||||
print('end success import_regulation_section_to_elastic')
|
print('end success import_regulation_section_to_elastic')
|
||||||
t2= datetime.datetime.now()
|
t2= datetime.datetime.now()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from app.common.text_normalizer import TextNormalizer
|
|||||||
# ضرورتا
|
# ضرورتا
|
||||||
# این برنامه ضرورت دارد اجرا شود
|
# این برنامه ضرورت دارد اجرا شود
|
||||||
|
|
||||||
def import_law_section_update_ref_state(cursor):
|
def import_law_section_update_ref_state(cursor, elastic, index_name_o) :
|
||||||
query = '''
|
query = '''
|
||||||
SELECT
|
SELECT
|
||||||
gl1.ID as id,
|
gl1.ID as id,
|
||||||
@@ -52,7 +52,7 @@ def import_law_section_update_ref_state(cursor):
|
|||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/section/multi/update"
|
# url = BASE_URL + "repo/majles/section/multi/update"
|
||||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
@@ -148,11 +148,15 @@ def import_law_section_update_ref_state(cursor):
|
|||||||
|
|
||||||
|
|
||||||
data={
|
data={
|
||||||
'id' : previd,
|
|
||||||
'ref_state' : ref_state_array
|
'ref_state' : ref_state_array
|
||||||
}
|
}
|
||||||
|
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : previd,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
ref_state_array = []
|
ref_state_array = []
|
||||||
previd = eid
|
previd = eid
|
||||||
@@ -163,24 +167,8 @@ def import_law_section_update_ref_state(cursor):
|
|||||||
if len(bulk_data) >= 100:
|
if len(bulk_data) >= 100:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' law_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
print('=' * 10, ' law_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
@@ -190,17 +178,20 @@ def import_law_section_update_ref_state(cursor):
|
|||||||
|
|
||||||
if ref_state_array.__len__() > 0 :
|
if ref_state_array.__len__() > 0 :
|
||||||
data={
|
data={
|
||||||
'id' : previd,
|
|
||||||
'ref_state' : ref_state_array
|
'ref_state' : ref_state_array
|
||||||
}
|
}
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
# print(bulk_data)
|
{
|
||||||
|
'_id' : previd,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
if len(bulk_data) > 0:
|
if len(bulk_data) > 0:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' law_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
print('=' * 10, ' law_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
bulk_data = []
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
|
|
||||||
print('end success import_law_section_update_ref_state')
|
print('end success import_law_section_update_ref_state')
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ from app.common.text_normalizer import TextNormalizer
|
|||||||
# این برنامه ضرورت دارد اجرا شود
|
# این برنامه ضرورت دارد اجرا شود
|
||||||
|
|
||||||
|
|
||||||
def import_regulation_section_update_ref_state(cursor):
|
def import_regulation_section_update_ref_state(cursor, elastic, index_name_o) :
|
||||||
query = '''
|
query = '''
|
||||||
SELECT
|
SELECT
|
||||||
gl1.ID as id,
|
gl1.ID as id,
|
||||||
@@ -54,7 +54,7 @@ def import_regulation_section_update_ref_state(cursor):
|
|||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/rgsection/multi/update"
|
# url = BASE_URL + "repo/majles/rgsection/multi/update"
|
||||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
@@ -149,11 +149,16 @@ def import_regulation_section_update_ref_state(cursor):
|
|||||||
|
|
||||||
|
|
||||||
data={
|
data={
|
||||||
'id' : previd,
|
|
||||||
'ref_state' : ref_state_array
|
'ref_state' : ref_state_array
|
||||||
}
|
}
|
||||||
|
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : previd,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
ref_state_array = []
|
ref_state_array = []
|
||||||
previd = eid
|
previd = eid
|
||||||
@@ -164,24 +169,8 @@ def import_regulation_section_update_ref_state(cursor):
|
|||||||
if len(bulk_data) >= 100:
|
if len(bulk_data) >= 100:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' regulation_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
print('=' * 10, ' regulation_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
@@ -190,18 +179,22 @@ def import_regulation_section_update_ref_state(cursor):
|
|||||||
|
|
||||||
if ref_state_array.__len__() > 0 :
|
if ref_state_array.__len__() > 0 :
|
||||||
data={
|
data={
|
||||||
'id' : previd,
|
|
||||||
'ref_state' : ref_state_array
|
'ref_state' : ref_state_array
|
||||||
}
|
}
|
||||||
bulk_data.append(data)
|
|
||||||
# print(bulk_data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : previd,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if len(bulk_data) > 0:
|
if len(bulk_data) > 0:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' regulation_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
print('=' * 10, ' regulation_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
bulk_data = []
|
||||||
# print(response.text)
|
|
||||||
|
|
||||||
print('end success import_regulation_section_update_ref_state')
|
print('end success import_regulation_section_update_ref_state')
|
||||||
t2= datetime.datetime.now()
|
t2= datetime.datetime.now()
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from app.common.config_base import *
|
|||||||
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
|
||||||
|
|
||||||
def import_law_reg_qanon_to_elastic(cursor):
|
def import_law_reg_qanon_to_elastic(cursor, elastic, index_name_o) :
|
||||||
|
|
||||||
query = '''
|
query = '''
|
||||||
SELECT
|
SELECT
|
||||||
@@ -21,6 +21,8 @@ def import_law_reg_qanon_to_elastic(cursor):
|
|||||||
--,[F_LWBASETABLEID_LAWTYPE]
|
--,[F_LWBASETABLEID_LAWTYPE]
|
||||||
,l1.[ISLAW] -- قانون
|
,l1.[ISLAW] -- قانون
|
||||||
,l1.[ISREGULATION] -- مقرره
|
,l1.[ISREGULATION] -- مقرره
|
||||||
|
,l1.[ISCORRECTIONLETTER] -- نامه اصلاحی
|
||||||
|
,l1.[ISOPINION] -- آراء
|
||||||
,isnull(l1.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
,isnull(l1.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
||||||
,isnull(l1.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
,isnull(l1.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
||||||
--,[F_LWBASETABLEID_CLASSIFICATION]
|
--,[F_LWBASETABLEID_CLASSIFICATION]
|
||||||
@@ -43,12 +45,28 @@ def import_law_reg_qanon_to_elastic(cursor):
|
|||||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||||
where l1.ID = l2.id
|
where l1.ID = l2.id
|
||||||
) as regulationType
|
) as regulationType
|
||||||
|
,(
|
||||||
|
SELECT isnull(op_r.CAPTION,'') as opinionType
|
||||||
|
FROM opOpinion o
|
||||||
|
left join opOpiniongiver op_r on o.F_OPOPINIONGIVERID = op_r.id
|
||||||
|
where l1.ID = o.F_LWLAWID
|
||||||
|
) as opinionType
|
||||||
|
,(
|
||||||
|
SELECT isnull(o.[OPINIONDATE],'') as opinionData
|
||||||
|
FROM opOpinion o
|
||||||
|
where l1.ID = o.F_LWLAWID
|
||||||
|
) as opinionData
|
||||||
|
,(
|
||||||
|
SELECT isnull(o.[ARCHIVENO],'') as opinionNumber
|
||||||
|
FROM opOpinion o
|
||||||
|
where l1.ID = o.F_LWLAWID
|
||||||
|
) as opinionNumber
|
||||||
|
|
||||||
FROM [Qavanin].[dbo].[lwLaw] l1
|
FROM [Qavanin].[dbo].[lwLaw] l1
|
||||||
left JOIN cmBasetable cbt ON l1.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
left JOIN cmBasetable cbt ON l1.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
||||||
left join lwLawSectionStatus lss on lss.id= l1.[F_CMBASETABLEID_LASTSTATUS]
|
left join lwLawSectionStatus lss on lss.id= l1.[F_CMBASETABLEID_LASTSTATUS]
|
||||||
|
|
||||||
where ( l1.ISLAW = 1 or l1.ISREGULATION = 1 )
|
where ( l1.ISLAW = 1 or l1.ISREGULATION = 1 or l1.ISOPINION = 1 )
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
@@ -58,7 +76,7 @@ def import_law_reg_qanon_to_elastic(cursor):
|
|||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/qaqanon/multi/add"
|
# url = BASE_URL + "repo/majles/qaqanon/multi/add"
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
|
|
||||||
@@ -81,8 +99,15 @@ def import_law_reg_qanon_to_elastic(cursor):
|
|||||||
|
|
||||||
|
|
||||||
title = text_normal.normalize_qanon( row.title )
|
title = text_normal.normalize_qanon( row.title )
|
||||||
|
title_type=''
|
||||||
|
if(row.ISOPINION == 1):
|
||||||
|
title_type=''
|
||||||
|
else:
|
||||||
title_type = getTitleType(title)
|
title_type = getTitleType(title)
|
||||||
|
|
||||||
|
if(row.ISCORRECTIONLETTER == 1):
|
||||||
|
title_type = 'نامه'
|
||||||
|
|
||||||
eid='qq'+ str(row.Id)
|
eid='qq'+ str(row.Id)
|
||||||
|
|
||||||
main_type = ''
|
main_type = ''
|
||||||
@@ -90,36 +115,60 @@ def import_law_reg_qanon_to_elastic(cursor):
|
|||||||
main_type = 'قانون'
|
main_type = 'قانون'
|
||||||
elif(row.ISREGULATION == 1):
|
elif(row.ISREGULATION == 1):
|
||||||
main_type = 'مقرره'
|
main_type = 'مقرره'
|
||||||
|
elif(row.ISOPINION == 1):
|
||||||
|
main_type = 'آراء'
|
||||||
|
|
||||||
|
ts_ref = normalYehKe(row.ts_ref)
|
||||||
sub_type = ''
|
sub_type = ''
|
||||||
if(row.ISLAW == 1):
|
if(row.ISLAW == 1):
|
||||||
sub_type = row.lawType
|
sub_type = row.lawType
|
||||||
elif(row.ISREGULATION == 1):
|
elif(row.ISREGULATION == 1):
|
||||||
sub_type = row.regulationType
|
sub_type = row.regulationType
|
||||||
|
elif(row.ISOPINION == 1):
|
||||||
|
sub_type = row.opinionType
|
||||||
|
if sub_type :
|
||||||
sub_type = normalYehKe(sub_type)
|
sub_type = normalYehKe(sub_type)
|
||||||
|
ts_ref = normalYehKe(sub_type)
|
||||||
|
ts_ref = ts_ref.replace("رای وحدت رویه", "")
|
||||||
|
ts_ref = ts_ref.replace("رای", "")
|
||||||
|
ts_ref = ts_ref.replace("نظر", "")
|
||||||
|
ts_ref = ts_ref.replace("- اصول 85 و 138", "")
|
||||||
|
ts_ref = ts_ref.strip()
|
||||||
|
else :
|
||||||
|
sub_type = ''
|
||||||
|
ts_ref = ''
|
||||||
|
|
||||||
|
if sub_type :
|
||||||
|
sub_type = normalYehKe(sub_type)
|
||||||
|
|
||||||
|
|
||||||
qanon_number = ''
|
qanon_number = ''
|
||||||
if(row.ISLAW == 1):
|
if(row.ISLAW == 1):
|
||||||
qanon_number = row.LAWNO
|
qanon_number = row.LAWNO
|
||||||
elif(row.ISREGULATION == 1):
|
elif(row.ISREGULATION == 1):
|
||||||
qanon_number = row.RULENO
|
qanon_number = row.RULENO
|
||||||
|
elif(row.ISOPINION == 1):
|
||||||
# other_type = 'اصلی' اصلاحی....
|
qanon_number = row.opinionNumber
|
||||||
# action_type ...
|
|
||||||
|
|
||||||
|
|
||||||
|
aproveDate=''
|
||||||
|
if(row.ISLAW == 1):
|
||||||
|
aproveDate = row.aproveDate
|
||||||
|
elif(row.ISREGULATION == 1):
|
||||||
|
aproveDate = row.aproveDate
|
||||||
|
elif(row.ISOPINION == 1):
|
||||||
|
aproveDate = row.opinionData
|
||||||
|
|
||||||
ts_year = ''
|
ts_year = ''
|
||||||
if row.aproveDate :
|
if aproveDate :
|
||||||
items = row.aproveDate.split("/")
|
items = aproveDate.split("/")
|
||||||
if items.__len__() > 0:
|
if items.__len__() > 0:
|
||||||
ts_year = items[0]
|
ts_year = items[0]
|
||||||
|
|
||||||
ts_ref = normalYehKe(row.ts_ref)
|
|
||||||
|
|
||||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||||
try:
|
try:
|
||||||
sort_date_timestamp = getSortTimestamp(row.aproveDate)
|
sort_date_timestamp = getSortTimestamp(aproveDate)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||||
|
|
||||||
@@ -138,7 +187,7 @@ def import_law_reg_qanon_to_elastic(cursor):
|
|||||||
'title': title,
|
'title': title,
|
||||||
'title_type': title_type,
|
'title_type': title_type,
|
||||||
'expire_date': expire_date,
|
'expire_date': expire_date,
|
||||||
'ts_date': row.aproveDate,
|
'ts_date': aproveDate,
|
||||||
'ts_year': ts_year,
|
'ts_year': ts_year,
|
||||||
'ts_ref': ts_ref,
|
'ts_ref': ts_ref,
|
||||||
'qanon_etebar' : qanon_etebar,
|
'qanon_etebar' : qanon_etebar,
|
||||||
@@ -148,38 +197,26 @@ def import_law_reg_qanon_to_elastic(cursor):
|
|||||||
if len(bulk_data) >= 100:
|
if len(bulk_data) >= 100:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' law_reg_qanon_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
print('=' * 10, ' law_reg_qanon_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||||
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
|
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if len(bulk_data) > 0:
|
if len(bulk_data) > 0:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' law_reg_qanon_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
print('=' * 10, ' law_reg_qanon_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.importBulkList(bulk_data, index_name_o)
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
bulk_data = []
|
||||||
|
|
||||||
print('end success law_reg_qanon_to_elastic ')
|
print('end success law_reg_qanon_to_elastic ')
|
||||||
t2= datetime.datetime.now()
|
t2= datetime.datetime.now()
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from app.common.general_functions import *
|
|||||||
from app.common.text_normalizer import TextNormalizer
|
from app.common.text_normalizer import TextNormalizer
|
||||||
|
|
||||||
|
|
||||||
def import_relations_qanon_lwreg(cursor):
|
def import_relations_qanon_lwreg(cursor, elastic, index_name_o) :
|
||||||
# اجرای کوئری SQL و خواندن دادهها به یک DataFrame
|
# اجرای کوئری SQL و خواندن دادهها به یک DataFrame
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
@@ -38,7 +38,7 @@ def import_relations_qanon_lwreg(cursor):
|
|||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
# url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
|
|
||||||
@@ -134,16 +134,19 @@ def import_relations_qanon_lwreg(cursor):
|
|||||||
continue
|
continue
|
||||||
else :
|
else :
|
||||||
data={
|
data={
|
||||||
'id' : prev_eid,
|
|
||||||
'qanon_relations' : relations
|
'qanon_relations' : relations
|
||||||
}
|
}
|
||||||
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : prev_eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
total_count = total_count+1
|
total_count = total_count+1
|
||||||
# if total_count < 2560 :
|
# if total_count < 2560 :
|
||||||
# continue
|
# continue
|
||||||
|
|
||||||
bulk_data.append(data)
|
|
||||||
|
|
||||||
prev_eid = eid
|
prev_eid = eid
|
||||||
relations=[]
|
relations=[]
|
||||||
relations.append(relation)
|
relations.append(relation)
|
||||||
@@ -152,24 +155,8 @@ def import_relations_qanon_lwreg(cursor):
|
|||||||
if len(bulk_data) >= 10:
|
if len(bulk_data) >= 10:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' relations_qanon_lwreg , total='+str(total_count) , str(i)+ ', id=' + eid )
|
print('=' * 10, ' relations_qanon_lwreg , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
@@ -178,34 +165,23 @@ def import_relations_qanon_lwreg(cursor):
|
|||||||
|
|
||||||
if len(relations) :
|
if len(relations) :
|
||||||
data={
|
data={
|
||||||
'id' : prev_eid,
|
|
||||||
'qanon_relations' : relations
|
'qanon_relations' : relations
|
||||||
}
|
}
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : prev_eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
while len(bulk_data) > 0 :
|
|
||||||
|
if len(bulk_data) > 0 :
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' relations_qanon_lwreg , total='+str(total_count))
|
print('=' * 10, ' relations_qanon_lwreg , total='+str(total_count))
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(bulk_data)
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
if not bulk_data :
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
t2= datetime.datetime.now()
|
t2= datetime.datetime.now()
|
||||||
print("finished time: " + str(t2))
|
print("finished time: " + str(t2))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from app.common.config_base import *
|
|||||||
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
|
||||||
|
|
||||||
def import_relations_qanon_opinion(cursor):
|
def import_relations_qanon_opinion(cursor, elastic, index_name_o) :
|
||||||
# اجرای کوئری SQL و خواندن دادهها به یک DataFrame
|
# اجرای کوئری SQL و خواندن دادهها به یک DataFrame
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
@@ -39,7 +39,7 @@ def import_relations_qanon_opinion(cursor):
|
|||||||
cursor.execute(query)
|
cursor.execute(query)
|
||||||
text_normal = TextNormalizer()
|
text_normal = TextNormalizer()
|
||||||
|
|
||||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
# url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||||
|
|
||||||
headers = HEADERS
|
headers = HEADERS
|
||||||
|
|
||||||
@@ -138,10 +138,14 @@ def import_relations_qanon_opinion(cursor):
|
|||||||
continue
|
continue
|
||||||
else :
|
else :
|
||||||
data={
|
data={
|
||||||
'id' : prev_eid,
|
|
||||||
'opinion_relations' : relations
|
'opinion_relations' : relations
|
||||||
}
|
}
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : prev_eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
prev_eid = eid
|
prev_eid = eid
|
||||||
relations=[]
|
relations=[]
|
||||||
@@ -151,25 +155,8 @@ def import_relations_qanon_opinion(cursor):
|
|||||||
if len(bulk_data) >= 10:
|
if len(bulk_data) >= 10:
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' relations_qanon_opinion , total='+str(total_count) , str(i)+ ', id=' + eid )
|
print('=' * 10, ' relations_qanon_opinion , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
# limit POST Content-Length 8388608
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(bulk_data)
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
break
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
# print(response)
|
||||||
# print(response.text)
|
# print(response.text)
|
||||||
# print(row.txt)
|
# print(row.txt)
|
||||||
@@ -178,33 +165,21 @@ def import_relations_qanon_opinion(cursor):
|
|||||||
|
|
||||||
if len(relations) > 0 :
|
if len(relations) > 0 :
|
||||||
data={
|
data={
|
||||||
'id' : prev_eid,
|
|
||||||
'opinion_relations' : relations
|
'opinion_relations' : relations
|
||||||
}
|
}
|
||||||
bulk_data.append(data)
|
bulk_data.append(
|
||||||
|
{
|
||||||
|
'_id' : prev_eid,
|
||||||
|
'_source' : data
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
while len(bulk_data) > 0 :
|
if len(bulk_data) > 0 :
|
||||||
total_count += len(bulk_data)
|
total_count += len(bulk_data)
|
||||||
print('=' * 10, ' relations_qanon_opinion , total='+str(total_count))
|
print('=' * 10, ' relations_qanon_opinion , total='+str(total_count))
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
elastic.updateBulkList(bulk_data, index_name_o)
|
||||||
|
|
||||||
pops_data = []
|
|
||||||
while len(payload) > 8388608 :
|
|
||||||
el = bulk_data.pop()
|
|
||||||
total_count -= 1
|
|
||||||
pops_data.append(el)
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print(bulk_data)
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = []
|
bulk_data = []
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
if not bulk_data :
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
t2= datetime.datetime.now()
|
t2= datetime.datetime.now()
|
||||||
print("update rows count: " + str(len(all_data)))
|
print("update rows count: " + str(len(all_data)))
|
||||||
|
|||||||
@@ -0,0 +1,463 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from tqdm import tqdm
|
||||||
|
import unicodedata
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||||
|
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
|
||||||
|
)
|
||||||
|
|
||||||
|
base_folder = r"E:\pdf advar"
|
||||||
|
|
||||||
|
# بعد انقلاب
|
||||||
|
col_shomare_parvande_after = "شماره پرونده"
|
||||||
|
col_doreh_after = "دوره قانونگذاری"
|
||||||
|
col_ts_ref = "مرجع تصویب"
|
||||||
|
|
||||||
|
# قبل انقلاب
|
||||||
|
col_shomare_koli_before = "شماره کلی"
|
||||||
|
col_shomare_parvande_before = "شماره پرونده و ردیف "
|
||||||
|
col_tarikh_before = "تاريختصويب 1"
|
||||||
|
col_doreh_before = "دوره قانونگذاری"
|
||||||
|
col_lib_folder_before = "شماره فولدر کتابخانه"
|
||||||
|
|
||||||
|
error_descriptions = {
|
||||||
|
"پوشه دوره پیدا نشد": "دوره قانونی در مسیر مشخص وجود ندارد، پوشه متناظر با دوره پیدا نشد.",
|
||||||
|
"مسیر دوره وجود ندارد": "مسیر دوره در سیستم وجود ندارد (احتمالاً مسیر اصلی اشتباه است).",
|
||||||
|
"پوشه پیدا نشد": "پوشه با شماره پرونده مشخص در مسیر دوره وجود ندارد.",
|
||||||
|
"نبود فایل": "هیچ فایل PDF یا عکس در پوشه یا زیرپوشه پیدا نشد.",
|
||||||
|
"بدون خطا": "پوشه و فایلها موجود هستند و تطابق لازم برقرار است.",
|
||||||
|
"عدم تطابق با شماره فولدر کتابخانه": "فایل عکس موجود است اما نام آن با شماره فولدر کتابخانه تطابق ندارد.",
|
||||||
|
"خطای زیر پوشه": "پوشه شامل زیرپوشه است، بررسی فایلها طبق قوانین انجام میشود.",
|
||||||
|
"خطای زیر پوشه / وجود فایل / بدون خطا": "زیرپوشه دارد و فایل PDF یا عکس مطابق شماره فولدر موجود است، بدون خطا ثبت میشود.",
|
||||||
|
"خطای زیر پوشه / وجود فایل / عدم تطابق با شماره فولدر کتابخانه": "زیرپوشه دارد و فایل عکس موجود است اما نام فایل مطابق شماره فولدر نیست.",
|
||||||
|
"دوره نامعتبر": "دوره قانونگذاری به صورت متنی است و عدد آن قابل استخراج نیست.",
|
||||||
|
"دوره نامعتبر (عدد X خارج از محدوده 1-12)": "عدد استخراجشده از دوره خارج از محدوده مجاز است.",
|
||||||
|
"فایل یا پوشه ای با این شماره پرونده پیدا نشد": "در مسیر مربوطه، هیچ فایل یا پوشهای با این نام وجود ندارد.",
|
||||||
|
"مطابق با الگو نبود": "شماره پرونده با الگوی تعریفشده مطابقت ندارد.",
|
||||||
|
"دوره (مجلس تشخیص)": "مصوبه مجلس تشخیص",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
doreh_to_folder_after = {str(i): f"d.{i}" for i in range(1, 13)} # d.1 تا d.12
|
||||||
|
|
||||||
|
doreh_to_folder_before = {
|
||||||
|
"اول": "d1-ok",
|
||||||
|
"دوم": "d2-ok",
|
||||||
|
"سوم": "d3-ok",
|
||||||
|
"چهارم": "d4-ok",
|
||||||
|
"پنجم": "d5-ok",
|
||||||
|
"ششم": "d6-ok",
|
||||||
|
"هفتم": "d7-ok",
|
||||||
|
"هشتم": "d8-ok",
|
||||||
|
"نهم": "d9-ok",
|
||||||
|
"دهم": "d10-ok",
|
||||||
|
"یازدهم": "d11-ok",
|
||||||
|
"دوازدهم": "d12-ok",
|
||||||
|
"سیزدهم": "d13-ok",
|
||||||
|
"چهاردهم": "d14-ok",
|
||||||
|
"پانزدهم": "d15-ok",
|
||||||
|
"شانزدهم": "d16-ok",
|
||||||
|
"هفدهم": "d17-ok",
|
||||||
|
"هجدهم": "d18-ok",
|
||||||
|
"نوزدهم": "d19-ok",
|
||||||
|
"بیستم": "d20-ok",
|
||||||
|
"بیست و یکم": "d21-ok",
|
||||||
|
"بیست و دوم": "d22-ok",
|
||||||
|
"بیست و سوم": "d23-ok",
|
||||||
|
"بیست و چهارم": "d24-ok",
|
||||||
|
}
|
||||||
|
|
||||||
|
# الگوی شماره پرونده بعد انقلاب
|
||||||
|
pattern_after = r"^\d+(?:\s*مکرر)?(?:/|\s*)?ش?\s*(?:مکرر)?\d*$"
|
||||||
|
|
||||||
|
# الگوی قبل انقلاب
|
||||||
|
pattern_before = r"^\d+$|^\d+\s*مکرر\d*$"
|
||||||
|
|
||||||
|
|
||||||
|
# نرمالسازی برای مقایسه دقیق
|
||||||
|
def normalize_str(s):
|
||||||
|
if not isinstance(s, str):
|
||||||
|
return ""
|
||||||
|
return unicodedata.normalize("NFKC", s).replace(" ", "").casefold()
|
||||||
|
|
||||||
|
|
||||||
|
# استخراج عدد
|
||||||
|
def extract_period_number(text):
|
||||||
|
if not isinstance(text, str):
|
||||||
|
return None
|
||||||
|
text = text.strip().lower()
|
||||||
|
|
||||||
|
num_match = re.match(r"^(\d+)", text)
|
||||||
|
if num_match:
|
||||||
|
return int(num_match.group(1))
|
||||||
|
|
||||||
|
number_map = {
|
||||||
|
"اول": 1,
|
||||||
|
"دوم": 2,
|
||||||
|
"سوم": 3,
|
||||||
|
"چهارم": 4,
|
||||||
|
"پنجم": 5,
|
||||||
|
"ششم": 6,
|
||||||
|
"هفتم": 7,
|
||||||
|
"هشتم": 8,
|
||||||
|
"نهم": 9,
|
||||||
|
"دهم": 10,
|
||||||
|
"یازدهم": 11,
|
||||||
|
"دوازدهم": 12,
|
||||||
|
}
|
||||||
|
for word, num in number_map.items():
|
||||||
|
if word in text:
|
||||||
|
return num
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_file_number(s):
|
||||||
|
if not isinstance(s, str):
|
||||||
|
return ""
|
||||||
|
s = s.translate(str.maketrans("۰۱۲۳۴۵۶۷۸۹", "0123456789"))
|
||||||
|
s = unicodedata.normalize("NFKC", s)
|
||||||
|
s = s.replace(" ", "").replace("/", "").casefold()
|
||||||
|
return s
|
||||||
|
|
||||||
|
# --- پردازش بعد انقلاب ---
|
||||||
|
def process_after_simple(df, period_map, base_subfolder_name):
|
||||||
|
df = df.copy()
|
||||||
|
df["وجود فایل"] = ""
|
||||||
|
df["تطابق با الگو"] = ""
|
||||||
|
df["مدیریت خطا"] = ""
|
||||||
|
df["مسیر"] = ""
|
||||||
|
df["فایلها"] = ""
|
||||||
|
|
||||||
|
|
||||||
|
folder_cache = {}
|
||||||
|
|
||||||
|
|
||||||
|
for idx, row in tqdm(df.iterrows(), total=len(df), desc="پردازش بعد انقلاب"):
|
||||||
|
try:
|
||||||
|
|
||||||
|
full_path=''
|
||||||
|
name_files=''
|
||||||
|
ts_ref_val = (
|
||||||
|
str(row[col_ts_ref]).strip()
|
||||||
|
if not pd.isna(row[col_ts_ref])
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
|
||||||
|
shomare_parvande_val = (
|
||||||
|
str(row[col_shomare_parvande_after]).strip()
|
||||||
|
if not pd.isna(row[col_shomare_parvande_after])
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
doreh_val = (
|
||||||
|
str(row[col_doreh_after]).strip()
|
||||||
|
if not pd.isna(row[col_doreh_after])
|
||||||
|
else ""
|
||||||
|
)
|
||||||
|
|
||||||
|
if doreh_val=='اول':
|
||||||
|
doreh_val='1'
|
||||||
|
elif doreh_val=='دوم':
|
||||||
|
doreh_val='2'
|
||||||
|
elif doreh_val=='سوم':
|
||||||
|
doreh_val='3'
|
||||||
|
elif doreh_val=='چهارم':
|
||||||
|
doreh_val='4'
|
||||||
|
elif doreh_val=='پنجم':
|
||||||
|
doreh_val='5'
|
||||||
|
elif doreh_val=='ششم':
|
||||||
|
doreh_val='6'
|
||||||
|
elif doreh_val=='هفتم':
|
||||||
|
doreh_val='7'
|
||||||
|
elif doreh_val=='هشتم':
|
||||||
|
doreh_val='8'
|
||||||
|
elif doreh_val=='نهم':
|
||||||
|
doreh_val='9'
|
||||||
|
elif doreh_val=='دهم':
|
||||||
|
doreh_val='10'
|
||||||
|
elif doreh_val=='یازدهم':
|
||||||
|
doreh_val='11'
|
||||||
|
elif doreh_val=='دوازدهم':
|
||||||
|
doreh_val='12'
|
||||||
|
elif doreh_val=='سیزدهم':
|
||||||
|
doreh_val='13'
|
||||||
|
elif doreh_val in ["...", "…", "........."]:
|
||||||
|
if ts_ref_val == 'شوراي انقلاب جمهوري اسلامي ايران' :
|
||||||
|
doreh_val='شورای انقلاب'
|
||||||
|
elif ts_ref_val == 'مجمع تشخيص مصلحت نظام' :
|
||||||
|
df.at[idx, "وجود فایل"] = "ندارد"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = "دوره نامعتبر"
|
||||||
|
continue
|
||||||
|
else :
|
||||||
|
df.at[idx, "وجود فایل"] = "ندارد"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = "دوره نامعتبر"
|
||||||
|
continue
|
||||||
|
|
||||||
|
full_path = ''
|
||||||
|
if doreh_val == 'شورای انقلاب':
|
||||||
|
shomare_parvande_val = shomare_parvande_val.replace("/", "")
|
||||||
|
search_name = shomare_parvande_val
|
||||||
|
norm_search = normalize_file_number(search_name)
|
||||||
|
full_path = os.path.join(
|
||||||
|
base_folder,
|
||||||
|
base_subfolder_name,
|
||||||
|
"shorayeh enghelab",
|
||||||
|
"مصوبات به تفکیک شمار پرونده"
|
||||||
|
)
|
||||||
|
|
||||||
|
else :
|
||||||
|
search_name=shomare_parvande_val
|
||||||
|
shomare_parvande_val=shomare_parvande_val.replace(".", "/")
|
||||||
|
# parts = shomare_parvande_val.split("/", 1)
|
||||||
|
parts = shomare_parvande_val.split("/")
|
||||||
|
if len(parts) == 2 :
|
||||||
|
search_name = parts[1].strip()
|
||||||
|
if doreh_val=='':
|
||||||
|
doreh_val = parts[0].strip()
|
||||||
|
else:
|
||||||
|
search_name = parts[0].strip()
|
||||||
|
|
||||||
|
norm_search = normalize_file_number(search_name)
|
||||||
|
period_num = doreh_val
|
||||||
|
period_folder = period_map.get(str(period_num))
|
||||||
|
|
||||||
|
if not period_folder:
|
||||||
|
df.at[idx, "وجود فایل"] = "ندارد"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = "دوره نامعتبر"
|
||||||
|
continue
|
||||||
|
|
||||||
|
full_path = os.path.join(
|
||||||
|
base_folder, base_subfolder_name, period_folder
|
||||||
|
)
|
||||||
|
|
||||||
|
if full_path not in folder_cache:
|
||||||
|
folder_cache[full_path] = (
|
||||||
|
set(os.listdir(full_path))
|
||||||
|
if os.path.exists(full_path) and os.path.isdir(full_path)
|
||||||
|
else set()
|
||||||
|
)
|
||||||
|
|
||||||
|
if not folder_cache[full_path]:
|
||||||
|
logging.warning(f"پوشه وجود ندارد یا خالی: {full_path}")
|
||||||
|
|
||||||
|
folder_contents = folder_cache[full_path]
|
||||||
|
|
||||||
|
found_file_name = None
|
||||||
|
for f in folder_contents:
|
||||||
|
root, ext = os.path.splitext(f)
|
||||||
|
if normalize_file_number(root).startswith(norm_search):
|
||||||
|
found_file_name = f
|
||||||
|
break
|
||||||
|
|
||||||
|
# df.at[idx, "وجود فایل"] = "دارد" if found_file_name else "ندارد"
|
||||||
|
# df.at[idx, "مسیر"] = (full_path +"/" + norm_search).replace(base_folder,'')
|
||||||
|
|
||||||
|
if not found_file_name :
|
||||||
|
df.at[idx, "مسیر"] = full_path.replace(base_folder,'')
|
||||||
|
df.at[idx, "وجود فایل"] = "ندارد"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = (
|
||||||
|
"فایل یا پوشه ای با این شماره پرونده پیدا نشد"
|
||||||
|
)
|
||||||
|
|
||||||
|
else :
|
||||||
|
df.at[idx, "وجود فایل"] = "دارد"
|
||||||
|
df.at[idx, "مسیر"] = full_path.replace(base_folder,'')
|
||||||
|
name_files = os.path.basename(found_file_name) + ','
|
||||||
|
df.at[idx, "فایلها"] = name_files
|
||||||
|
|
||||||
|
if re.match(pattern_after, normalize_file_number(shomare_parvande_val)):
|
||||||
|
df.at[idx, "تطابق با الگو"] = "مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = "بدون خطا"
|
||||||
|
else:
|
||||||
|
df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = "مطابق با الگو نبود"
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
df.at[idx, "وجود فایل"] = "نامشخص"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "نامشخص"
|
||||||
|
df.at[idx, "مدیریت خطا"] = f"خطا در ردیف {idx}: {str(e)}"
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
# --- پردازش قبل انقلاب ---
|
||||||
|
def process_dataframe_before(df, period_map, base_subfolder):
|
||||||
|
df = df.copy()
|
||||||
|
df["وضعیت وجود پوشه"] = ""
|
||||||
|
df["تطابق با الگو"] = ""
|
||||||
|
df["بررسی زیر پوشه"] = ""
|
||||||
|
df["وجود فایل"] = ""
|
||||||
|
df["مدیریت خطا"] = ""
|
||||||
|
df["مسیر"] = ""
|
||||||
|
df["فایلها"] = ""
|
||||||
|
|
||||||
|
for idx, row in tqdm(df.iterrows(), total=len(df), desc=f"پردازش {base_subfolder}"):
|
||||||
|
try:
|
||||||
|
shomare_parvande_val = str(row[col_shomare_parvande_before]).strip()
|
||||||
|
doreh_val = str(row[col_doreh_before]).strip()
|
||||||
|
lib_folder_val = str(row[col_lib_folder_before]).strip()
|
||||||
|
|
||||||
|
period_folder = period_map.get(doreh_val)
|
||||||
|
if not period_folder:
|
||||||
|
df.at[idx, "وضعیت وجود پوشه"] = "ندارد"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = "پوشه دوره پیدا نشد"
|
||||||
|
continue
|
||||||
|
|
||||||
|
target_folder_name_clean = shomare_parvande_val.replace(" ", "").strip()
|
||||||
|
full_path = os.path.join(base_folder, base_subfolder, period_folder, target_folder_name_clean)
|
||||||
|
df.at[idx, "مسیر"] = full_path.replace(base_folder,'')
|
||||||
|
found_folders = []
|
||||||
|
# print(full_path)
|
||||||
|
if not os.path.exists(full_path):
|
||||||
|
df.at[idx, "وضعیت وجود پوشه"] = "ندارد"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
df.at[idx, "مدیریت خطا"] = "پوشه پیدا نشد"
|
||||||
|
continue
|
||||||
|
|
||||||
|
# for d in os.listdir(full_path):
|
||||||
|
# folder_path = os.path.join(full_path, d)
|
||||||
|
# if (
|
||||||
|
# os.path.isdir(folder_path)
|
||||||
|
# and d.replace(" ", "").strip() == target_folder_name_clean
|
||||||
|
# ):
|
||||||
|
# found_folders.append(folder_path)
|
||||||
|
# if not found_folders:
|
||||||
|
# df.at[idx, "وضعیت وجود پوشه"] = "ندارد"
|
||||||
|
# df.at[idx, "تطابق با الگو"] = "غیر مطابق"
|
||||||
|
# df.at[idx, "مدیریت خطا"] = "پوشه پیدا نشد"
|
||||||
|
# continue
|
||||||
|
|
||||||
|
df.at[idx, "وضعیت وجود پوشه"] = "دارد"
|
||||||
|
df.at[idx, "تطابق با الگو"] = (
|
||||||
|
"مطابق"
|
||||||
|
if re.match(pattern_before, shomare_parvande_val.replace(" ", ""))
|
||||||
|
else "غیر مطابق"
|
||||||
|
)
|
||||||
|
|
||||||
|
has_file = False
|
||||||
|
pdf_found = False
|
||||||
|
subfolder_error = ""
|
||||||
|
matched_file = False
|
||||||
|
|
||||||
|
name_files= ''
|
||||||
|
|
||||||
|
for root, dirs, files in os.walk(full_path):
|
||||||
|
df.at[idx, "بررسی زیر پوشه"] = "دارد" if dirs else "ندارد"
|
||||||
|
if dirs:
|
||||||
|
subfolder_error = "خطای زیر پوشه"
|
||||||
|
for f in files:
|
||||||
|
f_lower = f.lower()
|
||||||
|
name_files += os.path.basename(f_lower) + ','
|
||||||
|
|
||||||
|
if f_lower.endswith(".pdf"):
|
||||||
|
pdf_found = True
|
||||||
|
has_file = True
|
||||||
|
elif f_lower.endswith(
|
||||||
|
(".jpg", ".jpeg", ".png", ".tif", ".bmp")
|
||||||
|
):
|
||||||
|
has_file = True
|
||||||
|
if (
|
||||||
|
lib_folder_val
|
||||||
|
and lib_folder_val.lower() != "nan"
|
||||||
|
and lib_folder_val.replace(" ", "").strip()
|
||||||
|
in os.path.splitext(f)[0].replace(" ", "").strip()
|
||||||
|
):
|
||||||
|
matched_file = True
|
||||||
|
|
||||||
|
if not has_file:
|
||||||
|
df.at[idx, "وجود فایل"] = "ندارد"
|
||||||
|
df.at[idx, "مدیریت خطا"] = (
|
||||||
|
subfolder_error if subfolder_error else "نبود فایل"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
df.at[idx, "وجود فایل"] = "دارد"
|
||||||
|
if subfolder_error:
|
||||||
|
if pdf_found or matched_file:
|
||||||
|
df.at[idx, "مدیریت خطا"] = (
|
||||||
|
f"{subfolder_error} / وجود فایل / بدون خطا"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
df.at[idx, "مدیریت خطا"] = (
|
||||||
|
f"{subfolder_error} / وجود فایل / عدم تطابق با شماره فولدر کتابخانه"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
if pdf_found or matched_file:
|
||||||
|
df.at[idx, "مدیریت خطا"] = "بدون خطا"
|
||||||
|
else:
|
||||||
|
df.at[idx, "مدیریت خطا"] = "عدم تطابق با شماره فولدر کتابخانه"
|
||||||
|
|
||||||
|
df.at[idx, "فایلها"] = name_files
|
||||||
|
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
df.at[idx, "وضعیت وجود پوشه"] = "نامشخص"
|
||||||
|
df.at[idx, "تطابق با الگو"] = "نامشخص"
|
||||||
|
df.at[idx, "مدیریت خطا"] = str(e)
|
||||||
|
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
|
def prepare_error_report(result_df, sheet_name):
|
||||||
|
df = result_df.copy()
|
||||||
|
counts = df["مدیریت خطا"].value_counts().reset_index()
|
||||||
|
counts.columns = ["خطا", "تعداد"]
|
||||||
|
counts["زمان"] = sheet_name
|
||||||
|
counts["توضیح"] = counts["خطا"].map(error_descriptions)
|
||||||
|
return counts[["خطا", "زمان", "توضیح", "تعداد"]]
|
||||||
|
|
||||||
|
|
||||||
|
def main_proccess():
|
||||||
|
# excel_file = "data/qavanin_files/qavanin.xlsx"
|
||||||
|
# output_file = "data/qavanin_files/qavanin_output2.xlsx"
|
||||||
|
# df_before = pd.read_excel(excel_file, sheet_name=0)
|
||||||
|
# df_after = pd.read_excel(excel_file, sheet_name=1)
|
||||||
|
|
||||||
|
excel_file1 = "data/qavanin_files/فهرست تمام قوانین_1_ 1 الی2378-رشیدزاده.xlsx"
|
||||||
|
excel_file2 = "data/qavanin_files/فهرست تمام قوانین_2_تکمیل شده.xlsx"
|
||||||
|
output_file = "data/qavanin_files/qavanin_output4.xlsx"
|
||||||
|
df_before = pd.read_excel(excel_file1, sheet_name=0)
|
||||||
|
df_after = pd.read_excel(excel_file2, sheet_name=0)
|
||||||
|
|
||||||
|
|
||||||
|
result_before = process_dataframe_before(
|
||||||
|
df_before,
|
||||||
|
doreh_to_folder_before,
|
||||||
|
os.path.join("ghabl az enghelab", "majlis shorayeh melli"),
|
||||||
|
)
|
||||||
|
result_after = process_after_simple(
|
||||||
|
df_after, doreh_to_folder_after, "baed az enghelab eslami"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
errors_before = prepare_error_report(result_before, "قبل انقلاب")
|
||||||
|
errors_after = prepare_error_report(result_after, "بعد انقلاب")
|
||||||
|
|
||||||
|
errors_combined = pd.concat([errors_before, errors_after], ignore_index=True)
|
||||||
|
|
||||||
|
os.makedirs("files", exist_ok=True)
|
||||||
|
with pd.ExcelWriter(output_file, engine="openpyxl") as writer:
|
||||||
|
result_before.to_excel(writer, index=False, sheet_name="قبل انقلاب")
|
||||||
|
result_after.to_excel(writer, index=False, sheet_name="بعد انقلاب")
|
||||||
|
errors_combined.to_excel(writer, index=False, sheet_name="گزارش کلی")
|
||||||
|
|
||||||
|
print(f"✅ خروجی نهایی ذخیره شد در: {output_file}")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main_proccess()
|
||||||
@@ -0,0 +1,558 @@
|
|||||||
|
import pandas as pd
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
from tqdm import tqdm
|
||||||
|
import unicodedata
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import sys
|
||||||
|
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from ..common.text_normalizer import TextNormalizer
|
||||||
|
# from general import *
|
||||||
|
from ..common.general_functions import *
|
||||||
|
from ..common.elastic_helper import ElasticHelper
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------
|
||||||
|
# قبل انقلاب
|
||||||
|
# خواندن اطلاعات اکسل و درج در qaqanon
|
||||||
|
# ....... تصمیمات قانونی داخل اکسل فیلد نوع دارند
|
||||||
|
# ---------------------------------------------
|
||||||
|
|
||||||
|
# ---------------------------------------------
|
||||||
|
# بعد انقلاب
|
||||||
|
# خواندن اطلاعات اکسل و درج در qaqanon
|
||||||
|
# برای تصمیمات قانونی، خواندن اکسل مخصوص و درج در qaqanon
|
||||||
|
# ---------------------------------------------
|
||||||
|
|
||||||
|
def import_excel_before_to_elastic(elastic, path_file, index_name_o):
|
||||||
|
bulk_data_import=[]
|
||||||
|
bulk_data_update=[]
|
||||||
|
total_count = 0
|
||||||
|
count = 0
|
||||||
|
id = ""
|
||||||
|
try:
|
||||||
|
|
||||||
|
data = excel_to_json(path_file, None, 0)
|
||||||
|
|
||||||
|
print('*' * 20 , ' count=', len(data))
|
||||||
|
cols = [
|
||||||
|
"شماره کلی",
|
||||||
|
"شماره ردیف با احتساب مکرر",
|
||||||
|
"شماره پرونده و ردیف ",
|
||||||
|
"دوره قانونگذاری",
|
||||||
|
"عنوان",
|
||||||
|
"تاریخ تصویب در dotic ",
|
||||||
|
"تاريختصويب 1",
|
||||||
|
"مرجع تصويب ",
|
||||||
|
"تاریخ تصویب 2",
|
||||||
|
"مرجع تصویب 2",
|
||||||
|
"نوع",
|
||||||
|
"شماره پرونده های مرتبط",
|
||||||
|
"وضعيت",
|
||||||
|
"اصلی/تبعی",
|
||||||
|
"بررسی کننده",
|
||||||
|
"تایید نهایی",
|
||||||
|
"شماره فولدر کتابخانه",
|
||||||
|
"توضیحات",
|
||||||
|
"شماره پرونده سنا",
|
||||||
|
"_id",
|
||||||
|
# "error",
|
||||||
|
# "Unnamed: 21",
|
||||||
|
# "Unnamed: 22",
|
||||||
|
# "Unnamed: 23",
|
||||||
|
# "Unnamed: 24",
|
||||||
|
# "وضعیت وجود پوشه",
|
||||||
|
# "تطابق با الگو",
|
||||||
|
# "بررسی زیر پوشه",
|
||||||
|
# "وجود فایل",
|
||||||
|
"مدیریت خطا",
|
||||||
|
"مسیر",
|
||||||
|
"فایلها"
|
||||||
|
]
|
||||||
|
|
||||||
|
text_normalizer = TextNormalizer()
|
||||||
|
for item in data:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
error_files_state = item.get("مدیریت خطا", "")
|
||||||
|
title = item.get("عنوان", "")
|
||||||
|
title = text_normalizer.normalize_qanon(title)
|
||||||
|
|
||||||
|
sub_type = item.get("نوع", "")
|
||||||
|
sub_type = text_normalizer.normalize_qanon(sub_type)
|
||||||
|
|
||||||
|
_id = item.get("_id", "")
|
||||||
|
davam_type = ''
|
||||||
|
eid = _id
|
||||||
|
|
||||||
|
number_all = item.get("شماره کلی", "")
|
||||||
|
|
||||||
|
|
||||||
|
number_row_duplicate = item.get("شماره ردیف با احتساب مکرر", "")
|
||||||
|
number_row_duplicate = number_row_duplicate if not '..' in number_row_duplicate else ''
|
||||||
|
|
||||||
|
number_row = item.get("شماره پرونده و ردیف ", "")
|
||||||
|
number_row = number_row if not '..' in number_row else ''
|
||||||
|
|
||||||
|
number_lib_folder = item.get("شماره فولدر کتابخانه", "")
|
||||||
|
number_lib_folder = number_lib_folder if not '..' in number_lib_folder else ''
|
||||||
|
|
||||||
|
number_sena = item.get("شماره پرونده سنا", "")
|
||||||
|
number_sena = number_sena if not '..' in number_sena else ''
|
||||||
|
|
||||||
|
description = item.get("توضیحات", "")
|
||||||
|
description = text_normalizer.normalize_qanon(description)
|
||||||
|
|
||||||
|
term = item.get("دوره قانونگذاری", "") # ???? term
|
||||||
|
term = text_normalizer.normalize_qanon(term)
|
||||||
|
term = term if not '..' in term else ''
|
||||||
|
|
||||||
|
ts_date_dotic = item.get("تاریخ تصویب در dotic ", "")
|
||||||
|
if not is_match_persian_date_format(ts_date_dotic):
|
||||||
|
ts_date_dotic = ''
|
||||||
|
|
||||||
|
|
||||||
|
ts_date1 = item.get("تاريختصويب 1", "")
|
||||||
|
if not is_match_persian_date_format(ts_date1):
|
||||||
|
ts_date1 = ''
|
||||||
|
|
||||||
|
ts_ref1 = item.get("مرجع تصويب ", "") # ????? ts_ref
|
||||||
|
ts_ref1 = text_normalizer.normalize_qanon(ts_ref1)
|
||||||
|
ts_ref1 = ts_ref1 if not '..' in ts_ref1 else ''
|
||||||
|
|
||||||
|
ts_date2 = item.get("تاریخ تصویب 2", "")
|
||||||
|
if not is_match_persian_date_format(ts_date2):
|
||||||
|
ts_date2 = ''
|
||||||
|
|
||||||
|
ts_ref2 = item.get("مرجع تصویب 2", "")
|
||||||
|
ts_ref2 = text_normalizer.normalize_qanon(ts_ref2)
|
||||||
|
ts_ref2 = ts_ref2 if not '..' in ts_ref2 else ''
|
||||||
|
|
||||||
|
qanon_etebar = item.get("وضعيت", "")
|
||||||
|
qanon_etebar = text_normalizer.normalize_qanon(qanon_etebar)
|
||||||
|
qanon_etebar = qanon_etebar if not '..' in qanon_etebar else ''
|
||||||
|
|
||||||
|
path_folder = item.get("مسیر", "")
|
||||||
|
name_files = item.get("فایلها", "")
|
||||||
|
|
||||||
|
# title = item.get("شماره پرونده های مرتبط", "") # فیلد معادل ندارد
|
||||||
|
# title = item.get("اصلی/تبعی", "") # فیلد معادل ندارد
|
||||||
|
# title = item.get("بررسی کننده", "") # فیلد معادل ندارد
|
||||||
|
# title = item.get("تایید نهایی", "") # فیلد معادل ندارد
|
||||||
|
|
||||||
|
main_type='قانون'
|
||||||
|
if sub_type == 'تصمیم قانونی' :
|
||||||
|
main_type = 'تصمیم قانونی'
|
||||||
|
sub_type=''
|
||||||
|
elif sub_type == 'علدی' :
|
||||||
|
sub_type='عادی'
|
||||||
|
elif sub_type == '...' :
|
||||||
|
if title.startswith('تصمیم قانونی') or title.startswith('تصویب نامه قانونی') :
|
||||||
|
sub_type=''
|
||||||
|
main_type = 'تصمیم قانونی'
|
||||||
|
else :
|
||||||
|
sub_type='بودجه'
|
||||||
|
else:
|
||||||
|
print('.#'*10,'error subtype , ', count)
|
||||||
|
|
||||||
|
is_update = True
|
||||||
|
if not _id.startswith('qq') :
|
||||||
|
eid = 0
|
||||||
|
is_update= False
|
||||||
|
if sub_type =='تصمیم قانونی' :
|
||||||
|
eid='qt_'+ uuid.uuid4().hex[:8]
|
||||||
|
else :
|
||||||
|
eid='qe_'+ uuid.uuid4().hex[:8]
|
||||||
|
sub_type='نامشخص'
|
||||||
|
if _id=='قانون جدید - موقت' :
|
||||||
|
davam_type='موقت'
|
||||||
|
sub_type='عادی'
|
||||||
|
|
||||||
|
|
||||||
|
files_info=[]
|
||||||
|
for name in name_files.split(','):
|
||||||
|
if not name :
|
||||||
|
continue
|
||||||
|
file_type = ''
|
||||||
|
if name.endswith(".pdf"):
|
||||||
|
file_type="pdf"
|
||||||
|
elif name.endswith(
|
||||||
|
(".jpg", ".jpeg", ".png", ".tif", ".bmp")
|
||||||
|
):
|
||||||
|
file_type="img"
|
||||||
|
else :
|
||||||
|
file_type=""
|
||||||
|
files_info.append({
|
||||||
|
"path": os.path.join(path_folder, name),
|
||||||
|
"file_name": name,
|
||||||
|
"title": name,
|
||||||
|
"type": file_type
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"title": title,
|
||||||
|
"main_type": main_type,
|
||||||
|
"sub_type": sub_type,
|
||||||
|
"term": term,
|
||||||
|
"qanon_etebar": qanon_etebar,
|
||||||
|
"davam_type": davam_type,
|
||||||
|
"ts_date_dotic": ts_date_dotic,
|
||||||
|
"ts_date1": ts_date1,
|
||||||
|
"ts_ref1": ts_ref1,
|
||||||
|
"ts_date2": ts_date2,
|
||||||
|
"ts_ref2": ts_ref2,
|
||||||
|
"description": description,
|
||||||
|
"files": files_info,
|
||||||
|
"number" :{
|
||||||
|
"all" : number_all,
|
||||||
|
"row_duplicate" : number_row_duplicate,
|
||||||
|
"row" : number_row,
|
||||||
|
"lib_folder" : number_lib_folder,
|
||||||
|
"sena" : number_sena
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_update :
|
||||||
|
bulk_data_update.append({
|
||||||
|
"_id": id,
|
||||||
|
"_source": data
|
||||||
|
})
|
||||||
|
else :
|
||||||
|
bulk_data_import.append({
|
||||||
|
"_id": id,
|
||||||
|
"_source": data
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if len(bulk_data_update) >= 100:
|
||||||
|
total_count += len(bulk_data_update)
|
||||||
|
print('=' * 10, ' update , total='+str(total_count) , str(count))
|
||||||
|
elastic.updateBulkList(bulk_data_update, index_name_o)
|
||||||
|
bulk_data_update = []
|
||||||
|
|
||||||
|
if len(bulk_data_import) >= 100:
|
||||||
|
total_count += len(bulk_data_import)
|
||||||
|
print('=' * 10, ' import , total='+str(total_count) , str(count))
|
||||||
|
elastic.importBulkList(bulk_data_import, index_name_o)
|
||||||
|
bulk_data_import = []
|
||||||
|
|
||||||
|
if len(bulk_data_update):
|
||||||
|
total_count += len(bulk_data_update)
|
||||||
|
print('=' * 10, ' update , total='+str(total_count) , str(count))
|
||||||
|
elastic.updateBulkList(bulk_data_update, index_name_o)
|
||||||
|
bulk_data_update = []
|
||||||
|
|
||||||
|
if len(bulk_data_import):
|
||||||
|
total_count += len(bulk_data_import)
|
||||||
|
print('=' * 10, ' import , total='+str(total_count) , str(count))
|
||||||
|
elastic.importBulkList(bulk_data_import, index_name_o)
|
||||||
|
bulk_data_import = []
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception: " + str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def import_excel_after_to_elastic(elastic, path_file, index_name_o):
|
||||||
|
bulk_data_import=[]
|
||||||
|
bulk_data_update=[]
|
||||||
|
total_count = 0
|
||||||
|
count = 0
|
||||||
|
id = ""
|
||||||
|
try:
|
||||||
|
|
||||||
|
data = excel_to_json(path_file, None, 0)
|
||||||
|
|
||||||
|
print('*' * 20 , ' count=', len(data))
|
||||||
|
cols = [
|
||||||
|
"شماره عمومی",
|
||||||
|
"شماره رديف",
|
||||||
|
"شماره پرونده",
|
||||||
|
"دوره قانونگذاری",
|
||||||
|
"عنوان",
|
||||||
|
"تاریخ تصویب",
|
||||||
|
"مرجع تصویب",
|
||||||
|
"تاریخ تایید",
|
||||||
|
"وضعيت",
|
||||||
|
"شماره روزنامه رسمی کشور",
|
||||||
|
"تاریخ انتشار روزنامه رسمی کشور",
|
||||||
|
"شماره شناسه قانون",
|
||||||
|
"شماره پرونده های مرتبط",
|
||||||
|
"اصلی/تبعی",
|
||||||
|
"مستندات",
|
||||||
|
" تصدیق کنندگان فایل word قانون با pdf",
|
||||||
|
"توضیحات تصدیق",
|
||||||
|
"تاریخ لازم الاجرا شدن",
|
||||||
|
" تطبیق کنندگان فایلpdf با روزنامه رسمی",
|
||||||
|
"توضیحات تطبیق فایلpdf با روزنامه رسمی",
|
||||||
|
"_id",
|
||||||
|
"error",
|
||||||
|
"وجود فایل",
|
||||||
|
"تطابق با الگو",
|
||||||
|
"مدیریت خطا",
|
||||||
|
"مسیر",
|
||||||
|
"فایلها"
|
||||||
|
]
|
||||||
|
|
||||||
|
text_normalizer = TextNormalizer()
|
||||||
|
for item in data:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
error_files_state = item.get("مدیریت خطا", "")
|
||||||
|
title = item.get("عنوان", "")
|
||||||
|
title = text_normalizer.normalize_qanon(tile)
|
||||||
|
_id = item.get("_id", "")
|
||||||
|
davam_type = ''
|
||||||
|
eid = _id
|
||||||
|
|
||||||
|
number_all = item.get("شماره عمومی", "")
|
||||||
|
number_row_duplicate = item.get("شماره ردیف", "")
|
||||||
|
number_row = item.get("شماره پرونده ", "")
|
||||||
|
|
||||||
|
ts_date = item.get("تاريختصويب", "")
|
||||||
|
if not is_match_persian_date_format(ts_date):
|
||||||
|
ts_date = ''
|
||||||
|
|
||||||
|
ts_ref = item.get("مرجع تصويب", "") # ????? ts_ref
|
||||||
|
ts_ref = text_normalizer.normalize_qanon(ts_ref)
|
||||||
|
|
||||||
|
shora_date = item.get("تاریخ تایید", "")
|
||||||
|
if not is_match_persian_date_format(shora_date):
|
||||||
|
shora_date = ''
|
||||||
|
exec_date = item.get("تاریخ لازم الاجرا شدن", "")
|
||||||
|
if not is_match_persian_date_format(exec_date):
|
||||||
|
exec_date = ''
|
||||||
|
|
||||||
|
rrk_number = item.get("شماره روزنامه رسمی کشور", "")
|
||||||
|
rrk_number = rrk_number if not '..' in rrk_number else ''
|
||||||
|
|
||||||
|
rrk_date = item.get("تاریخ انتشار روزنامه رسمی کشور", "")
|
||||||
|
if not is_match_persian_date_format(rrk_date):
|
||||||
|
rrk_date = ''
|
||||||
|
|
||||||
|
|
||||||
|
number_qanon = item.get("شماره شناسه قانون", "")
|
||||||
|
|
||||||
|
description = item.get("مستندات", "")
|
||||||
|
description = text_normalizer.normalize_qanon(description)
|
||||||
|
|
||||||
|
term = item.get("دوره قانونگذاری", "") # ???? term
|
||||||
|
term = text_normalizer.normalize_qanon(term)
|
||||||
|
term = term if not '..' in term else ''
|
||||||
|
|
||||||
|
qanon_etebar = item.get("وضعيت", "")
|
||||||
|
qanon_etebar = text_normalizer.normalize_qanon(qanon_etebar)
|
||||||
|
|
||||||
|
path_folder = item.get("مسیر", "")
|
||||||
|
name_files = item.get("فایلها", "")
|
||||||
|
|
||||||
|
# title = item.get("شماره پرونده های مرتبط", "") # فیلد معادل ندارد - تبعی های مرتبط و مثل این منظورهست که خودکار پر میشود یا سامانه می دهد
|
||||||
|
# title = item.get("اصلی/تبعی", "") # فیلد معادل ندارد
|
||||||
|
# title = item.get("بررسی کننده", "") # فیلد معادل ندارد
|
||||||
|
# title = item.get("تایید نهایی", "") # فیلد معادل ندارد
|
||||||
|
|
||||||
|
main_type='قانون'
|
||||||
|
sub_type = 'عادی'
|
||||||
|
|
||||||
|
letters = []
|
||||||
|
if shora_date :
|
||||||
|
letters.append({
|
||||||
|
"type" : "تایید شورای نگهبان",
|
||||||
|
"date" : shora_date
|
||||||
|
})
|
||||||
|
|
||||||
|
if rrk_number or rrk_date :
|
||||||
|
letters.append({
|
||||||
|
"type" : "انتشار در روزنامه رسمی",
|
||||||
|
"number" : rrk_number,
|
||||||
|
"date" : rrk_date
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
is_update = True
|
||||||
|
if not _id.startswith('qq') :
|
||||||
|
eid = 0
|
||||||
|
is_update= False
|
||||||
|
eid='qe_'+ uuid.uuid4().hex[:8]
|
||||||
|
sub_type='نامشخص'
|
||||||
|
|
||||||
|
|
||||||
|
files_info=[]
|
||||||
|
for name in name_files.split(','):
|
||||||
|
if not name :
|
||||||
|
continue
|
||||||
|
file_type = ''
|
||||||
|
if name.endswith(".pdf"):
|
||||||
|
file_type="pdf"
|
||||||
|
elif name.endswith(
|
||||||
|
(".jpg", ".jpeg", ".png", ".tif", ".bmp")
|
||||||
|
):
|
||||||
|
file_type="img"
|
||||||
|
else :
|
||||||
|
file_type=""
|
||||||
|
files_info.append({
|
||||||
|
"path": os.path.join(path_folder, name),
|
||||||
|
"file_name": name,
|
||||||
|
"title": name,
|
||||||
|
"type": file_type
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"title": title,
|
||||||
|
"main_type": main_type,
|
||||||
|
"sub_type": sub_type,
|
||||||
|
"term": term,
|
||||||
|
"qanon_etebar": qanon_etebar,
|
||||||
|
"davam_type": davam_type,
|
||||||
|
"ts_date_dotic": ts_date_dotic,
|
||||||
|
"ts_date1": ts_date1,
|
||||||
|
"ts_ref1": ts_ref1,
|
||||||
|
"ts_date2": ts_date2,
|
||||||
|
"ts_ref2": ts_ref2,
|
||||||
|
"description": description,
|
||||||
|
"files": files_info,
|
||||||
|
"number" :{
|
||||||
|
"all" : number_all,
|
||||||
|
"row_duplicate" : number_row_duplicate,
|
||||||
|
"row" : number_row,
|
||||||
|
"lib_folder" : number_lib_folder,
|
||||||
|
"sena" : number_sena
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if is_update :
|
||||||
|
bulk_data_update.append({
|
||||||
|
"_id": id,
|
||||||
|
"_source": data
|
||||||
|
})
|
||||||
|
else :
|
||||||
|
bulk_data_import.append({
|
||||||
|
"_id": id,
|
||||||
|
"_source": data
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if len(bulk_data_update) >= 100:
|
||||||
|
total_count += len(bulk_data_update)
|
||||||
|
print('=' * 10, ' update , total='+str(total_count) , str(count))
|
||||||
|
elastic.updateBulkList(bulk_data_update, index_name_o)
|
||||||
|
bulk_data_update = []
|
||||||
|
|
||||||
|
if len(bulk_data_import) >= 100:
|
||||||
|
total_count += len(bulk_data_import)
|
||||||
|
print('=' * 10, ' import , total='+str(total_count) , str(count))
|
||||||
|
elastic.importBulkList(bulk_data_import, index_name_o)
|
||||||
|
bulk_data_import = []
|
||||||
|
|
||||||
|
if len(bulk_data_update):
|
||||||
|
total_count += len(bulk_data_update)
|
||||||
|
print('=' * 10, ' update , total='+str(total_count) , str(count))
|
||||||
|
elastic.updateBulkList(bulk_data_update, index_name_o)
|
||||||
|
bulk_data_update = []
|
||||||
|
|
||||||
|
if len(bulk_data_import):
|
||||||
|
total_count += len(bulk_data_import)
|
||||||
|
print('=' * 10, ' import , total='+str(total_count) , str(count))
|
||||||
|
elastic.importBulkList(bulk_data_import, index_name_o)
|
||||||
|
bulk_data_import = []
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception: " + str(e))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def import_excel_tasmimat_to_elastic(elastic, path_file, index_name_o):
|
||||||
|
bulk_data_import=[]
|
||||||
|
total_count = 0
|
||||||
|
count = 0
|
||||||
|
id = ""
|
||||||
|
try:
|
||||||
|
|
||||||
|
data = excel_to_json(path_file, None, 0)
|
||||||
|
|
||||||
|
print('*' * 20 , ' count=', len(data))
|
||||||
|
cols = [
|
||||||
|
"ردیف",
|
||||||
|
"مستند قانونی",
|
||||||
|
"موضوع",
|
||||||
|
"نتیجه",
|
||||||
|
"جلسه",
|
||||||
|
"تاریخ",
|
||||||
|
]
|
||||||
|
|
||||||
|
text_normalizer = TextNormalizer()
|
||||||
|
for item in data:
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
row = item.get("ردیف", "")
|
||||||
|
description = item.get("مستند قانونی", "")
|
||||||
|
description = text_normalizer.normalize_qanon(description)
|
||||||
|
|
||||||
|
subject = item.get("موضوع", "")
|
||||||
|
subject = text_normalizer.normalize_qanon(subject)
|
||||||
|
|
||||||
|
content = item.get("نتیجه", "")
|
||||||
|
content = text_normalizer.normalize_qanon(content)
|
||||||
|
|
||||||
|
number = item.get("جلسه", "")
|
||||||
|
ts_date = item.get("تاریخ", "")
|
||||||
|
if not is_match_persian_date_format(ts_date):
|
||||||
|
ts_date = ''
|
||||||
|
print('.*'*10, ' error ts_date in ', row)
|
||||||
|
continue
|
||||||
|
|
||||||
|
title = subject + ' - جلسه ' + number + ' تاریخ ' + ts_date
|
||||||
|
|
||||||
|
main_type='تصمیم قانونی'
|
||||||
|
ts_ref='مجلس شورای اسلامی'
|
||||||
|
sub_type = ''
|
||||||
|
term = ''
|
||||||
|
|
||||||
|
is_update = False
|
||||||
|
|
||||||
|
eid ='qt_'+ uuid.uuid4().hex[:8]
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"id": eid,
|
||||||
|
"title": title,
|
||||||
|
"main_type": main_type,
|
||||||
|
"sub_type": sub_type,
|
||||||
|
"term": term,
|
||||||
|
"ts_date": ts_date,
|
||||||
|
"ts_ref": ts_ref,
|
||||||
|
"description": description,
|
||||||
|
"content": content
|
||||||
|
}
|
||||||
|
|
||||||
|
bulk_data_import.append({
|
||||||
|
"_id": id,
|
||||||
|
"_source": data
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
if len(bulk_data_import) >= 100:
|
||||||
|
total_count += len(bulk_data_import)
|
||||||
|
print('=' * 10, ' import , total='+str(total_count) , str(count))
|
||||||
|
elastic.importBulkList(bulk_data_import, index_name_o)
|
||||||
|
bulk_data_import = []
|
||||||
|
|
||||||
|
if len(bulk_data_import):
|
||||||
|
total_count += len(bulk_data_import)
|
||||||
|
print('=' * 10, ' import , total='+str(total_count) , str(count))
|
||||||
|
elastic.importBulkList(bulk_data_import, index_name_o)
|
||||||
|
bulk_data_import = []
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception: " + str(e))
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,794 @@
|
|||||||
|
{
|
||||||
|
"mappings": {
|
||||||
|
"date_detection": false,
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"fa": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "normal_analyzer_fa",
|
||||||
|
"search_analyzer": "normal_analyzer_fa",
|
||||||
|
"search_quote_analyzer": "phrase_analyzer_fa"
|
||||||
|
},
|
||||||
|
"ph": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "phrase_analyzer_fa",
|
||||||
|
"search_analyzer": "phrase_analyzer_fa",
|
||||||
|
"search_quote_analyzer": "phrase_analyzer_fa"
|
||||||
|
},
|
||||||
|
"keyword": {
|
||||||
|
"type": "keyword",
|
||||||
|
"ignore_above": 256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"title_popular": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "normal_analyzer_fa",
|
||||||
|
"search_analyzer": "normal_analyzer_fa",
|
||||||
|
"search_quote_analyzer": "phrase_analyzer_fa"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"fa": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "normal_analyzer_fa",
|
||||||
|
"search_analyzer": "normal_analyzer_fa",
|
||||||
|
"search_quote_analyzer": "phrase_analyzer_fa"
|
||||||
|
},
|
||||||
|
"ph": {
|
||||||
|
"type": "text",
|
||||||
|
"analyzer": "phrase_analyzer_fa",
|
||||||
|
"search_analyzer": "phrase_analyzer_fa",
|
||||||
|
"search_quote_analyzer": "phrase_analyzer_fa"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"embeddings": {
|
||||||
|
"type": "dense_vector",
|
||||||
|
"dims": 768,
|
||||||
|
"index": true,
|
||||||
|
"similarity": "cosine"
|
||||||
|
},
|
||||||
|
"initial": {
|
||||||
|
"properties": {
|
||||||
|
"title": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"approuve_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"creators": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"signers": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"approuve_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"approuve_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"letter_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"letter_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"letter_signer": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"ministers": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"properties": {
|
||||||
|
"path": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"file_name": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"receive": {
|
||||||
|
"properties": {
|
||||||
|
"term_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"ref_law": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"meet_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"meet_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"register_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"publish_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"handle_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"handle_method": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"refer": {
|
||||||
|
"properties": {
|
||||||
|
"refer_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"commission_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"commission_main": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"commission_mirrors": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"commission_common": {
|
||||||
|
"properties": {
|
||||||
|
"name": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"member_count": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"member_names": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"handle_85": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"commission_report": {
|
||||||
|
"properties": {
|
||||||
|
"agendas": {
|
||||||
|
"properties": {
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"meets": {
|
||||||
|
"properties": {
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"report_first": {
|
||||||
|
"properties": {
|
||||||
|
"approve_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"report_nexts": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"duration_85": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"date_85": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"parl_handle": {
|
||||||
|
"properties": {
|
||||||
|
"agendas": {
|
||||||
|
"properties": {
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"meets": {
|
||||||
|
"properties": {
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"agree_names": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"against_names": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"demands": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"demand85_names": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"handle_infos": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"duration_85": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"date_85": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"before_info": {
|
||||||
|
"properties": {
|
||||||
|
"ref_id": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"plan_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"discuss_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"ministers": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"creators": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"register_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"prev_number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"receipt_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"discuss_date1": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"discuss_date2": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"commission_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"commission_main": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"commission_mirrors": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"letters": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"sub_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"order": {
|
||||||
|
"type": "float"
|
||||||
|
},
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"content": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"delay_time": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"expire_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"properties": {
|
||||||
|
"path": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"file_name": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"counts": {
|
||||||
|
"properties": {
|
||||||
|
"key": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"davam_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"number": {
|
||||||
|
"properties": {
|
||||||
|
"row_duplicate": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"lib_folder": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"row": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"all": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"sena": {
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"archive_info": {
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ts_date_dotic": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"ts_date1": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"ts_ref1": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"ts_date2": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"ts_ref2": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"conformity_rrk": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"conformity_qanonyar": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"content_ocr": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"qanon_etebar": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"expire_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"exec_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"ref_key": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"ts_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"ts_year": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"ts_ref": {
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"keyword": {
|
||||||
|
"type": "keyword",
|
||||||
|
"ignore_above": 256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"term": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"term_number": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"ranking_weight": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"main_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"sub_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"title_type": {
|
||||||
|
"type": "text",
|
||||||
|
"fields": {
|
||||||
|
"keyword": {
|
||||||
|
"type": "keyword",
|
||||||
|
"ignore_above": 256
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"action_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"section_len": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"eblagh": {
|
||||||
|
"properties": {
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"from": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rrk": {
|
||||||
|
"properties": {
|
||||||
|
"number": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"date": {
|
||||||
|
"type": "date"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"exceuter_organs": {
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"receiver_organs": {
|
||||||
|
"properties": {
|
||||||
|
"id": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sort_date_timestamp": {
|
||||||
|
"type": "long"
|
||||||
|
},
|
||||||
|
"qanon_relations": {
|
||||||
|
"properties": {
|
||||||
|
"from_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"from_section_id": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"from_section_title": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"rel_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"to_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"to_id": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"to_title": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"wait": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"rel_key": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"opinion_relations": {
|
||||||
|
"properties": {
|
||||||
|
"from_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"from_section_id": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"from_section_title": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"rel_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"to_type": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"to_id": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"to_title": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"wait": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"rel_key": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"fixed_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"renewal_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"exec_duration": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"effective_date": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"relation_organs": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"files": {
|
||||||
|
"properties": {
|
||||||
|
"path": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"file_name": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"title": {
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"type": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"is_delete": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"time_edit": {
|
||||||
|
"type": "date"
|
||||||
|
},
|
||||||
|
"doc_tags": {
|
||||||
|
"type": "keyword"
|
||||||
|
},
|
||||||
|
"doc_states": {
|
||||||
|
"type": "keyword"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"index.max_result_window": 15000,
|
||||||
|
"index": {
|
||||||
|
"analysis": {
|
||||||
|
"analyzer": {
|
||||||
|
"phrase_analyzer_fa": {
|
||||||
|
"type": "custom",
|
||||||
|
"tokenizer": "standard",
|
||||||
|
"char_filter": [
|
||||||
|
"fa_char_filter"
|
||||||
|
],
|
||||||
|
"filter": []
|
||||||
|
},
|
||||||
|
"normal_analyzer_fa": {
|
||||||
|
"type": "custom",
|
||||||
|
"tokenizer": "standard",
|
||||||
|
"char_filter": [
|
||||||
|
"fa_char_filter"
|
||||||
|
],
|
||||||
|
"filter": [
|
||||||
|
"fa_stop"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"filter": {
|
||||||
|
"fa_stop": {
|
||||||
|
"type": "stop",
|
||||||
|
"stopwords": [
|
||||||
|
"یا",
|
||||||
|
"را",
|
||||||
|
"این",
|
||||||
|
"با",
|
||||||
|
"آن",
|
||||||
|
"و",
|
||||||
|
"در",
|
||||||
|
"به",
|
||||||
|
"که",
|
||||||
|
"از",
|
||||||
|
"طی",
|
||||||
|
"پس",
|
||||||
|
"چه",
|
||||||
|
"اگر",
|
||||||
|
"نه",
|
||||||
|
"آنها",
|
||||||
|
"هر",
|
||||||
|
"او",
|
||||||
|
"ما",
|
||||||
|
"من",
|
||||||
|
"تا",
|
||||||
|
"نیز",
|
||||||
|
"اما",
|
||||||
|
"یک",
|
||||||
|
"بر",
|
||||||
|
"هم",
|
||||||
|
"برای",
|
||||||
|
"کن",
|
||||||
|
"کرد",
|
||||||
|
"کردن",
|
||||||
|
"باش",
|
||||||
|
"بود",
|
||||||
|
"بودن",
|
||||||
|
"شو",
|
||||||
|
"شد",
|
||||||
|
"شدن",
|
||||||
|
"دار",
|
||||||
|
"داشت",
|
||||||
|
"داشتن",
|
||||||
|
"خواه",
|
||||||
|
"خواست",
|
||||||
|
"خواستن",
|
||||||
|
"گوی",
|
||||||
|
"گفت",
|
||||||
|
"گفتن",
|
||||||
|
"گیر",
|
||||||
|
"گرفت",
|
||||||
|
"گرفتن",
|
||||||
|
"آی",
|
||||||
|
"آمد",
|
||||||
|
"آمدن",
|
||||||
|
"توان",
|
||||||
|
"توانستن",
|
||||||
|
"یاب",
|
||||||
|
"یافتن",
|
||||||
|
"آور",
|
||||||
|
"آورد",
|
||||||
|
"آوردن",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"ص",
|
||||||
|
"4",
|
||||||
|
"و",
|
||||||
|
"5",
|
||||||
|
"ج",
|
||||||
|
"6",
|
||||||
|
"a",
|
||||||
|
"top",
|
||||||
|
"href",
|
||||||
|
"pageno"
|
||||||
|
],
|
||||||
|
"char_filter": []
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"char_filter": {
|
||||||
|
"fa_char_filter": {
|
||||||
|
"type": "mapping",
|
||||||
|
"mappings": [
|
||||||
|
"٠ => 0",
|
||||||
|
"١ => 1",
|
||||||
|
"٢ => 2",
|
||||||
|
"٣ => 3",
|
||||||
|
"٤ => 4",
|
||||||
|
"٥ => 5",
|
||||||
|
"٦ => 6",
|
||||||
|
"٧ => 7",
|
||||||
|
"٨ => 8",
|
||||||
|
"٩ => 9",
|
||||||
|
"ک => ك",
|
||||||
|
"ی => ي",
|
||||||
|
"ة => ه",
|
||||||
|
"إ => ا",
|
||||||
|
"أ => ا",
|
||||||
|
"آ => ا",
|
||||||
|
"ء => ا",
|
||||||
|
"َ => ",
|
||||||
|
"ُ => ",
|
||||||
|
"ِ => ",
|
||||||
|
"ّ => ",
|
||||||
|
"ً => ",
|
||||||
|
"ٌ => ",
|
||||||
|
"ٍ => ",
|
||||||
|
"ْ => "
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"number_of_shards": "1",
|
||||||
|
"number_of_replicas": "0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
این فایل در اولین فرصت پاک شود
|
|
||||||
@@ -0,0 +1,156 @@
|
|||||||
|
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 ..common.text_normalizer import TextNormalizer
|
||||||
|
# from general import *
|
||||||
|
from ..common.general_functions import *
|
||||||
|
from ..common.elastic_helper import ElasticHelper
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# text_normal = TextNormalizer()
|
||||||
|
|
||||||
|
|
||||||
|
def repair_persian_date(item, key, id, error_list, key2=''):
|
||||||
|
res = ''
|
||||||
|
path_key = key2+'.'+key if key2 else key
|
||||||
|
if key in item :
|
||||||
|
_date = item[key]
|
||||||
|
if not _date or _date == '' :
|
||||||
|
del item[key]
|
||||||
|
return item
|
||||||
|
|
||||||
|
if _date and not is_match_persian_date_format(_date):
|
||||||
|
error_list.append({'id':id, 'key': path_key, "value":_date, "message": "match_persian_date_format" })
|
||||||
|
del item[key]
|
||||||
|
return item
|
||||||
|
|
||||||
|
if _date :
|
||||||
|
try :
|
||||||
|
res = jdate2Gregorian(_date)
|
||||||
|
except Exception as e:
|
||||||
|
error_list.append({'id':id, 'key': path_key, "value":_date, "message": "convert persian_date" })
|
||||||
|
del item[key]
|
||||||
|
return item
|
||||||
|
|
||||||
|
if res :
|
||||||
|
item[key] = res
|
||||||
|
|
||||||
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
def correct_qanono_data_json( data, error_list ) :
|
||||||
|
data_new = []
|
||||||
|
for item in data :
|
||||||
|
id = item['_id']
|
||||||
|
item['_source'] = repair_persian_date(item['_source'], 'ts_date', id, error_list, '')
|
||||||
|
item['_source'] = repair_persian_date(item['_source'], 'exec_date', id, error_list, '')
|
||||||
|
item['_source'] = repair_persian_date(item['_source'], 'expire_date', id, error_list, '')
|
||||||
|
item['_source'] = repair_persian_date(item['_source'], 'fixed_date', id, error_list, '')
|
||||||
|
item['_source'] = repair_persian_date(item['_source'], 'renewal_date', id, error_list, '')
|
||||||
|
|
||||||
|
if 'eblagh' in item['_source'] :
|
||||||
|
item['_source']['eblagh'] = repair_persian_date(item['_source']['eblagh'], 'date', id, error_list, 'eblagh')
|
||||||
|
if 'rrk' in item['_source'] :
|
||||||
|
item['_source']['rrk'] = repair_persian_date(item['_source']['rrk'], 'date', id, error_list, 'rrk')
|
||||||
|
data_new.append(item)
|
||||||
|
return data_new
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def restore_correct_data_to_elastic(elastic, file_path, index_name ) :
|
||||||
|
error_list = []
|
||||||
|
fileNo = 0
|
||||||
|
with zipfile.ZipFile(file_path, "r") as zObject:
|
||||||
|
fileNo += 1
|
||||||
|
|
||||||
|
packNo = 0
|
||||||
|
counter = 0
|
||||||
|
for filename in zObject.namelist():
|
||||||
|
packNo += 1
|
||||||
|
|
||||||
|
# print("index:", index_name, "=>", filename)
|
||||||
|
data = []
|
||||||
|
with zObject.open(filename) as file:
|
||||||
|
data = json.loads(file.read())
|
||||||
|
|
||||||
|
data_new = correct_qanono_data_json(data, error_list)
|
||||||
|
elastic.importJsonDataToElastic(data_new, index_name, [], True)
|
||||||
|
counter += len(data)
|
||||||
|
# print('-'*10, 'len()', str(counter) + '/ ' + str(len(data)) + ' , ' +str(len(data_new)) )
|
||||||
|
|
||||||
|
|
||||||
|
elastic.es.indices.refresh(index=index_name)
|
||||||
|
print(elastic.es.cat.count(index=index_name, format="json"))
|
||||||
|
|
||||||
|
file_log_error = 'G:/Project2/160_dotic/date_log_error.txt'
|
||||||
|
with open(file_log_error, 'w', encoding='utf8') as f :
|
||||||
|
json.dump(error_list, f, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def import_data_new_qaqanon(elastic, path_file):
|
||||||
|
jsonData=[]
|
||||||
|
count = 0
|
||||||
|
id = ""
|
||||||
|
try:
|
||||||
|
|
||||||
|
try:
|
||||||
|
list_ = elastic.iterateJsonFile(path_file, True)
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception es_iterate_all_documents : " + str(e))
|
||||||
|
|
||||||
|
print('*' * 20 , ' count=', elastic.total)
|
||||||
|
|
||||||
|
for mentry in list(list_):
|
||||||
|
count += 1
|
||||||
|
entry = mentry["source"]
|
||||||
|
|
||||||
|
id = entry.get("id", "")
|
||||||
|
main_type = entry.get("main_type", "")
|
||||||
|
|
||||||
|
# قانونها را نباید بروزرسانی کنیم ...چون از طرف مجلس تغییرات شناسانامه در ایندکس داشته است
|
||||||
|
if(main_type == 'قانون') :
|
||||||
|
continue
|
||||||
|
|
||||||
|
jsonData.append({
|
||||||
|
"_id": id,
|
||||||
|
"_source": entry
|
||||||
|
})
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("Exception: " + str(e))
|
||||||
|
|
||||||
|
error_list = []
|
||||||
|
jsonData_new = correct_qanono_data_json(jsonData, error_list)
|
||||||
|
|
||||||
|
pack_size = 1000
|
||||||
|
bulk = []
|
||||||
|
total = len(jsonData_new)
|
||||||
|
count = 0
|
||||||
|
for item in jsonData_new:
|
||||||
|
bulk.append(item)
|
||||||
|
if len(bulk) >= pack_size :
|
||||||
|
count += len(bulk)
|
||||||
|
elastic.importJsonDataToElastic(bulk, "mj_qa_qanon")
|
||||||
|
print( ' count update ', str(count), '/', str(total))
|
||||||
|
bulk = []
|
||||||
|
|
||||||
|
if len(bulk):
|
||||||
|
count += len(bulk)
|
||||||
|
elastic.importJsonDataToElastic(bulk, "mj_qa_qanon")
|
||||||
|
print( ' count update ', str(count), '/', str(total))
|
||||||
|
bulk = []
|
||||||
|
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ from app.common.text_normalizer import TextNormalizer
|
|||||||
from app.common.general_functions import *
|
from app.common.general_functions import *
|
||||||
from app.common.elastic_helper import ElasticHelper
|
from app.common.elastic_helper import ElasticHelper
|
||||||
from app.for_ai.create_relation_tags import *
|
from app.for_ai.create_relation_tags import *
|
||||||
from app.temp_refactor_gn_dataset import *
|
# from app.temp_refactor_gn_dataset import *
|
||||||
|
|
||||||
load_dotenv(dotenv_path="config.env")
|
load_dotenv(dotenv_path="config.env")
|
||||||
|
|
||||||
@@ -48,12 +48,14 @@ 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)
|
||||||
|
|
||||||
|
|
||||||
|
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_qanon", "mj_qa_qanon_112")
|
||||||
|
|
||||||
# elastic.removeCustomFileds("mj_qa_section", ["tcode","nlp_parser","content_normal","tcode_mains","tcode_subs", "ners_v1", "level", "code-ai"])
|
# elastic.removeCustomFileds("mj_qa_section", ["tcode","nlp_parser","content_normal","tcode_mains","tcode_subs", "ners_v1", "level", "code-ai"])
|
||||||
|
|
||||||
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section-m1")
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_qa_section-m1")
|
||||||
# elastic.createIndex( index_name='mj_qa_section-m1', app_key='majles', map_name='mj_qa_section')
|
# elastic.createIndex( index_name='mj_qa_section-m1', app_key='majles', map_name='mj_qa_section')
|
||||||
# elastic.restorFileToElastic2('G:/Project2/111/mj_qa_section-m1.zip', 'mj_qa_section-m1', 'majles', False, 'mj_qa_section')
|
# elastic.restorFileToElastic2('G:/Project2/111/mj_qa_section-m1.zip', 'mj_qa_section-m1', 'majles', False, 'mj_qa_section')
|
||||||
elastic.restorFileToElastic2(path_file='G:/Project2/111/server112/mj_qa_section-m1.zip', index_name='mj_qa_section-m1', app_key='majles', queryDelete=False, map_name='mj_qa_section')
|
# elastic.restorFileToElastic2(path_file='G:/Project2/111/server112/mj_qa_section-m1.zip', index_name='mj_qa_section-m1', app_key='majles', queryDelete=False, map_name='mj_qa_section')
|
||||||
|
|
||||||
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_plan")
|
# elastic.backupIndexToZipfile("G:/Project2/111", "mj_plan")
|
||||||
# elastic.createIndex( 'mj_plan', 'majles', 'mj_plan')
|
# elastic.createIndex( 'mj_plan', 'majles', 'mj_plan')
|
||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user