all_sql_steps , repair qa_qanon
This commit is contained in:
@@ -1,594 +0,0 @@
|
||||
from time import time
|
||||
import requests
|
||||
from app.common.general_functions import *
|
||||
from app.common.config_base import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
|
||||
#def saveEmbedingContent()
|
||||
|
||||
##----- مرحله اول -----------------
|
||||
## پردازش و پرکردن فیلدهای متنوع کمکی
|
||||
def fill_nlp_tags(elasticHelper, index_name_o = "mj_qa_section_ai", path_resource='resource/my/') :
|
||||
id = ""
|
||||
body = {
|
||||
### این فهرست قوانینی است که تعداد زیادی از اجزاء دارای لول بزرگتر از 8 دارند
|
||||
# "query": {
|
||||
# "bool": {
|
||||
# "must_not": [
|
||||
# {
|
||||
# "terms": {
|
||||
# "qanon_id":["qq86911", "qq83307", "qq178971", "qq111830", "qq233930", "qq85434"]
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# },
|
||||
"sort": [
|
||||
{"qanon_id": {"order": "asc"}},
|
||||
{"child_order": {"order": "asc"}}
|
||||
]
|
||||
}
|
||||
|
||||
useful_ids = {}
|
||||
# useful_titles_al = []
|
||||
# useful_finded = []
|
||||
# خواندن کلمات موجود در فایل
|
||||
with open( path_resource+"qanon_usefull.txt", 'r', encoding='utf-8') as f:
|
||||
for line in f :
|
||||
id = line.strip().split('=')[0]
|
||||
if id not in useful_ids :
|
||||
useful_ids[id] = 1
|
||||
|
||||
|
||||
try:
|
||||
try:
|
||||
list = elasticHelper.es_iterate_all_documents(index_name_o, body)
|
||||
except Exception as e:
|
||||
save_error(0, e)
|
||||
count = 0
|
||||
print('*' * 20 , ' count=', elasticHelper.total)
|
||||
path_heading=[]
|
||||
level_parent= 0
|
||||
file_error = open('error_fill_nlp_tags.txt', 'w+', encoding='utf-8')
|
||||
|
||||
for mentry in list:
|
||||
count += 1
|
||||
entry = mentry["source"]
|
||||
|
||||
id = entry.get("id", "")
|
||||
#qanon_etebar = entry.get("qanon_etebar", "")
|
||||
state_etebar = entry.get("state_etebar", "")
|
||||
title_type = entry.get("title_type", "")
|
||||
qanon_title = entry.get("qanon_title", "")
|
||||
qanon_id = entry.get("qanon_id", "0")
|
||||
other_info = entry.get("other_info", {})
|
||||
parent_id = entry.get("parent_id", "0")
|
||||
content = entry.get("content", "")
|
||||
full_path = other_info["full_path"]
|
||||
nlp_tags = []
|
||||
|
||||
|
||||
#"full_path": "ماده واحده>فصل ششم>بخش سوم>قسمت چهارم>فصل هشتم>ماده 153>بند ب>جزء 4",
|
||||
paths = full_path.split('>')
|
||||
last_path = ''
|
||||
if paths :
|
||||
last_path = paths[-1]
|
||||
|
||||
level_2 = len(paths)
|
||||
|
||||
###--------------------شناسایی بزرگی کوچکی متن -------------------
|
||||
word_len = len(split_words(content))
|
||||
|
||||
###--------------------شناسایی بزرگی کوچکی متن -------------------
|
||||
if word_len > 100 :
|
||||
nlp_tags.append("words_big")
|
||||
elif word_len > 50 :
|
||||
nlp_tags.append("words_medium")
|
||||
else :
|
||||
nlp_tags.append("words_small")
|
||||
|
||||
|
||||
###--------------------شناسایی هدینگ بودن -------------------
|
||||
prefix, title, content_type = normalHeadingTitle(content, last_path)
|
||||
if not parent_id or parent_id == '0' or parent_id==0 :
|
||||
path_heading = []
|
||||
level_parent = 0
|
||||
|
||||
###--------------------شناسایی قوانین پرکاربرد -------------------
|
||||
if qanon_id in useful_ids:
|
||||
nlp_tags.append("qanon_usefull")
|
||||
|
||||
###-------------------- تعیین مسیر هدینگ -------------------
|
||||
## هرچند با پرنت آی دی این خالی می شود ولی برای مطمئن کاری این شرط اضافه شد
|
||||
elif full_path=='عنوان' or full_path=='موخره' or full_path=='امضاء' :
|
||||
path_heading = []
|
||||
level_parent = 0
|
||||
|
||||
elif level_2 < level_parent :
|
||||
diff = level_parent - level_2
|
||||
while diff > 0 and path_heading :
|
||||
path_heading.pop()
|
||||
diff = diff - 1
|
||||
|
||||
level_parent = level_2
|
||||
# print('id :', id , ' --diff ', diff, path_heading )
|
||||
|
||||
if level_2 >= level_parent :
|
||||
|
||||
# برای اجزاء بعدی شناسایی و ذخیره می شود نه جزء جاری
|
||||
if prefix != '' and title != '':
|
||||
if level_2 == level_parent and path_heading :
|
||||
path_heading.pop()
|
||||
|
||||
if len(title) < 256 :
|
||||
path_heading.append(title)
|
||||
nlp_tags.append("heading")
|
||||
level_parent = level_2
|
||||
###--------------------------------------------------------
|
||||
full_path_prev = full_path
|
||||
full_path = title_type + ' :: ' + full_path
|
||||
heading_in_content = ''
|
||||
|
||||
if "heading" in nlp_tags :
|
||||
nlp_tags.append("concept_no")
|
||||
elif 'تفسیر' in state_etebar or 'تفسیر' in last_path :
|
||||
nlp_tags.append("concept_side")
|
||||
elif 'عنوان' in last_path or 'موخره' in last_path or 'امضاء' in last_path or 'سربرگ' in last_path or 'فهرست' in last_path or 'منشور' in last_path :
|
||||
nlp_tags.append("concept_no")
|
||||
elif 'ماده' in last_path or 'اصل' in last_path or 'متن' in last_path or 'مقدمه' in last_path or 'نامه' in last_path or 'کلیات' in last_path or 'قسمت' in last_path or 'توضیح' in last_path or 'سوال' in last_path or 'استفساریه' in last_path :
|
||||
nlp_tags.append("concept_base")
|
||||
elif 'بند' in last_path or 'جزء' in last_path or 'زیرجزء' in last_path or 'شماره' in last_path or 'ردیف' in last_path or 'پاورقی' in last_path or 'اشاره' in last_path or 'تنبیه' in last_path or 'بخش' in last_path or 'جواب' in last_path or 'مقرره' in last_path :
|
||||
nlp_tags.append("concept_week")
|
||||
elif 'تبصره' in last_path or 'بخش' in last_path or 'تذکر' in last_path or 'توصیه' in last_path or 'توجه' in last_path :
|
||||
nlp_tags.append("concept_middle")
|
||||
elif 'الحاقی' in state_etebar or 'الحاقی' in last_path :
|
||||
nlp_tags.append("concept_week")
|
||||
elif 'جدول' in last_path :
|
||||
nlp_tags.append("concept_bad")
|
||||
elif content_type in ['تبصره','بخش','تذکر'] :
|
||||
nlp_tags.append("concept_middle")
|
||||
elif content_type in ['ماده'] :
|
||||
nlp_tags.append("concept_base")
|
||||
# elif qanon_etebar == 'منسوخه' :
|
||||
# pass
|
||||
elif 'پروتکل' in full_path or 'موافقتنامه' in full_path or 'قطعنامه' in full_path or 'پیوست' in full_path or 'عهدنامه' in full_path or 'توافقنامه' in full_path or 'معاهده' in full_path or 'کنوانسیون' in full_path or 'قرارداد' in full_path :
|
||||
if not title :
|
||||
nlp_tags.append("concept_bad")
|
||||
elif len(title) < 50 :
|
||||
if prefix :
|
||||
nlp_tags.append("concept_head")
|
||||
heading_in_content = title
|
||||
else :
|
||||
nlp_tags.append("concept_week")
|
||||
else :
|
||||
nlp_tags.append("concept_base")
|
||||
elif prefix :
|
||||
if title and len(title) < 50 :
|
||||
file_error.write('---***---- data id=' + id + ' full_path : ' + full_path + ' prefix : '+ prefix +' --- '+ title + '\n')
|
||||
print('---***---- data id=', id, ' full_path : ', full_path , ' prefix : ', prefix ,' --- ', title)
|
||||
else :
|
||||
if title and len(title) < 50:
|
||||
if 'فصل' in last_path or 'مبحث' in last_path :
|
||||
nlp_tags.append("concept_head")
|
||||
heading_in_content = title
|
||||
if full_path_prev == '' :
|
||||
nlp_tags.append("concept_bad")
|
||||
else :
|
||||
file_error.write('------- data id='+ id + ' full_path : '+ full_path + ' prefix : '+ prefix +' --- '+ title + '\n')
|
||||
print('------- data id=', id, ' full_path : ', full_path , ' prefix : ', prefix ,' --- ', title)
|
||||
elif len(title) >= 50 :
|
||||
if full_path_prev == '' :
|
||||
nlp_tags.append("concept_bad")
|
||||
else :
|
||||
file_error.write('### ####### error data id='+ id + ' full_path : '+ full_path + ' prefix : '+ prefix +' --- '+ title + '\n')
|
||||
print('### ####### error data id=', id, ' full_path : ', full_path , ' prefix : ', prefix ,' --- ', title)
|
||||
|
||||
###--------------------------------------------------------
|
||||
## فقط در همین جزء ثبت شود
|
||||
path_heading2 = path_heading
|
||||
if heading_in_content :
|
||||
path_heading2.append(heading_in_content)
|
||||
|
||||
## ----------------------------------------
|
||||
data = {}
|
||||
|
||||
data["nlp_tags"]= nlp_tags
|
||||
data["path_headings"]= path_heading2
|
||||
data["word_len"] = word_len
|
||||
data["level"]= level_2
|
||||
|
||||
update = True
|
||||
eid = id
|
||||
try:
|
||||
resp = elasticHelper.update_index_doc(update, index_name_o, eid, data)
|
||||
|
||||
except Exception as e:
|
||||
save_error(id, e)
|
||||
|
||||
|
||||
except Exception as e:
|
||||
save_error(id, e)
|
||||
# print("Exception: " + str(e))
|
||||
# print( e)
|
||||
# print("%s -> %.2f " % (id , (counter / total) if total > 0 else 0))
|
||||
# try:
|
||||
# print('ts_date:'+ts_date)
|
||||
# except:
|
||||
# print('not definded')
|
||||
|
||||
file_error.close()
|
||||
print("=" * 10, " fill_content_nlp finished")
|
||||
|
||||
|
||||
##----- مرحله دوم -----------------
|
||||
## شناسایی فرزندان اجزاء اصلی
|
||||
def extract_nlp_childs(elasticHelper, index_name_i = "mj_qa_section", index_name_o = "") :
|
||||
counter = 0
|
||||
total = 0
|
||||
id = ""
|
||||
body={
|
||||
"sort": [
|
||||
{"qanon_id": {"order": "asc"}},
|
||||
{"child_order": {"order": "desc"}}
|
||||
]
|
||||
}
|
||||
if not index_name_o :
|
||||
index_name_o = index_name_i
|
||||
dicParents = {}
|
||||
try:
|
||||
try:
|
||||
list = elasticHelper.es_iterate_all_documents(index_name_i, body)
|
||||
except Exception as e:
|
||||
save_error(0, e)
|
||||
count = 0
|
||||
qanon_id_prev = ""
|
||||
parent_id_prev = "0"
|
||||
count_normal = 0
|
||||
count_un_normal = 0
|
||||
for mentry in list:
|
||||
count += 1
|
||||
entry = mentry["source"]
|
||||
|
||||
id = entry.get("id", "")
|
||||
content = entry.get("content", "")
|
||||
path_headings = entry.get("path_headings", [])
|
||||
word_len = entry.get("word_len", [])
|
||||
qanon_id = entry.get("qanon_id", "0")
|
||||
parent_id = entry.get("parent_id", "0")
|
||||
nlp_tags = entry.get("nlp_tags", [])
|
||||
|
||||
## ثبت اطلاعات
|
||||
if qanon_id != qanon_id_prev and dicParents:
|
||||
list = []
|
||||
for key, value in dicParents.items():
|
||||
list.append({
|
||||
'_id': key,
|
||||
'_source': {
|
||||
"nlp_childs" : value
|
||||
}
|
||||
})
|
||||
word_len = 0
|
||||
for child in value :
|
||||
word_len += child["word_len"]
|
||||
|
||||
if word_len > 512 :
|
||||
count_un_normal +=1
|
||||
print('--- id', key , ' child_count:', len(value), ' words:', word_len, ' count_normal:', count_normal, ' count_un_normal:', count_un_normal)
|
||||
else :
|
||||
count_normal +=1
|
||||
|
||||
elasticHelper.updateBulkList(list, index_name_o)
|
||||
dicParents = {}
|
||||
|
||||
qanon_id_prev = qanon_id
|
||||
### نیازی به بردار سازی و جستجوی معنایی یا ارتباط یابی نیست
|
||||
if 'concept_no' in nlp_tags or 'concept_bad' in nlp_tags or 'concept_base' in nlp_tags :
|
||||
continue
|
||||
### تا حد امکان با محتوای اصلی قبل، بردار شود و همانجا ذخیره شود
|
||||
elif 'concept_week' in nlp_tags or 'concept_middle' in nlp_tags or 'concept_side' in nlp_tags :
|
||||
if parent_id and parent_id != '0' and parent_id != 0 :
|
||||
#if 'words_small' in nlp_tags or 'words_small' in nlp_tags :
|
||||
if parent_id not in dicParents :
|
||||
dicParents[parent_id] = []
|
||||
|
||||
dicParents[parent_id].append({
|
||||
"word_len": word_len,
|
||||
"id": id ,
|
||||
# "content" : content
|
||||
})
|
||||
continue
|
||||
|
||||
|
||||
except Exception as e:
|
||||
# save_error(id, e)
|
||||
print("Exception: " + e)
|
||||
print( e)
|
||||
print("%s -> %.2f " % (id , (counter / total) if total > 0 else 0))
|
||||
|
||||
|
||||
print("=" * 10, "import_data_embeding finished")
|
||||
|
||||
|
||||
##----- مرحله سوم -----------------
|
||||
## تولید بردار برای اجزاء به همراه اطلاعات کناری و کمکی
|
||||
def import_data_embeding(elasticHelper, ai_url_vec, index_name_i = "mj_qa_section", index_name_o = "mj_qa_section_ai", field_content="content") :
|
||||
|
||||
id = ""
|
||||
body={
|
||||
# "query": {
|
||||
# "bool": {
|
||||
# "must_not": [
|
||||
# {
|
||||
# "terms": {
|
||||
# "nlp_tags": ["concept_no","concept_bad"]
|
||||
# }
|
||||
# }
|
||||
# ]
|
||||
# }
|
||||
# },
|
||||
"sort": [
|
||||
{"qanon_id": {"order": "asc"}},
|
||||
{"child_order": {"order": "asc"}}
|
||||
]
|
||||
}
|
||||
|
||||
dicParents = {}
|
||||
try:
|
||||
try:
|
||||
list = elasticHelper.es_iterate_all_documents(index_name_i, body)
|
||||
except Exception as e:
|
||||
save_error(0, e)
|
||||
count = 0
|
||||
qanon_id_prev = ""
|
||||
parent_state = {}
|
||||
parent_entry = {}
|
||||
prev_entry_child = {}
|
||||
for mentry in list:
|
||||
count += 1
|
||||
entry = mentry["source"]
|
||||
|
||||
id = entry.get("id", "")
|
||||
content = entry.get(field_content, "")
|
||||
path_headings = entry.get("path_headings", [])
|
||||
qanon_title = entry.get("qanon_title", [])
|
||||
word_len = entry.get("word_len", [])
|
||||
qanon_id = entry.get("qanon_id", "0")
|
||||
parent_id = entry.get("parent_id", "0")
|
||||
nlp_tags = entry.get("nlp_tags", [])
|
||||
nlp_childs = entry.get("nlp_childs", [])
|
||||
|
||||
qanon_id_prev = qanon_id
|
||||
### نیازی به بردار سازی و جستجوی معنایی یا ارتباط یابی نیست
|
||||
if 'concept_no' in nlp_tags or 'concept_bad' in nlp_tags or not content:
|
||||
continue
|
||||
|
||||
content_emb = ''
|
||||
content_offset = ' '
|
||||
data = entry
|
||||
word_len_childs = 0
|
||||
if nlp_childs and len(nlp_childs) :
|
||||
|
||||
## اگر پدر و فرزندهای قبلی چیزی هنوز مونده ، بردارسازی باید شود
|
||||
if prev_entry_child :
|
||||
eid = prev_entry_child.get("id", "")
|
||||
content = prev_entry_child.get(field_content, "")
|
||||
data = prev_entry_child
|
||||
content_offset = parent_state["content_offset"]
|
||||
content_emb = parent_state["content"] + "\n" + content + "\n"+ parent_state["content_emb"]
|
||||
data["content_emb"] = content_emb
|
||||
prev_entry_child = {}
|
||||
|
||||
# word_len_childs = 0
|
||||
# for item in nlp_childs :
|
||||
# word_len_childs += item["word_len"]
|
||||
|
||||
#word_len_total = word_len + word_len_childs
|
||||
content_offset = 'در ' + qanon_title + ' درباره '
|
||||
for hed in path_headings :
|
||||
content_offset += ' ' + hed.strip()
|
||||
word_len_offset = len(split_words(content_offset))
|
||||
parent_state = {
|
||||
"id" : id,
|
||||
"word_len" : word_len,
|
||||
"word_len_offset" : word_len_offset,
|
||||
"nlp_childs" : nlp_childs,
|
||||
"content" : content,
|
||||
"content_offset" : content_offset,
|
||||
"word_len_childs" : 0,
|
||||
"content_emb" : "",
|
||||
"is_parent_embedded" : 0
|
||||
}
|
||||
parent_entry = entry
|
||||
### تا حد امکان با محتوای اصلی قبل، بردار شود و همانجا ذخیره شود
|
||||
elif 'concept_week' in nlp_tags or 'concept_middle' in nlp_tags or 'concept_side' in nlp_tags :
|
||||
if parent_state and parent_state["id"] == parent_id :
|
||||
wl = parent_state["word_len"]
|
||||
wl_of = parent_state["word_len_offset"]
|
||||
wl_em = parent_state["word_len_childs"]
|
||||
len_total = wl + wl_of + wl_em + word_len
|
||||
## اگر جا داره که با محتوای ماده اصلی=، بردار سازی باشد
|
||||
if len_total < 512 :
|
||||
parent_state["word_len_childs"] += word_len
|
||||
parent_state["content_emb"] = parent_state["content_emb"] + "\n" + content
|
||||
|
||||
## محتوای اصلی با بخشی از محتوای بندها و زیرجزءها، بردارسازی و ذخیره شود و مابقی در ادامه
|
||||
else :
|
||||
if parent_state["is_parent_embedded"] == 1: ## قبلا محتوای پدر با فرزندان در حد طول 512 بردارسازی شده و ذخیره شده است
|
||||
## حالا محتوای فرزندهای باقیمانده با کمک محتوای پدرا باید تا طول 512 بردارسازی شوند
|
||||
if prev_entry_child :
|
||||
eid = prev_entry_child.get("id", "")
|
||||
content = prev_entry_child.get(field_content, "")
|
||||
data = prev_entry_child
|
||||
content_offset = parent_state["content_offset"]
|
||||
content_emb = parent_state["content"] + "\n" + content + "\n"+ parent_state["content_emb"]
|
||||
data["content_emb"] = content_emb
|
||||
else : ## تست شد : پیش نمی آید
|
||||
print('------ no prev entry for child ####### error data id=', id, ' wl_em : ', wl_em, ' parent_id : ', parent_id , ' parent_state : ', parent_state["id"] )
|
||||
|
||||
prev_entry_child = entry
|
||||
parent_state["word_len_childs"] = 0
|
||||
parent_state["content_emb"] = ''
|
||||
|
||||
|
||||
elif parent_entry :
|
||||
|
||||
parent_state["is_parent_embedded"] = 1
|
||||
eid = parent_state["id"]
|
||||
data = parent_entry
|
||||
|
||||
content_offset = parent_state["content_offset"]
|
||||
content_emb = parent_state["content"] + "\n" + parent_state["content_emb"]
|
||||
data["content_emb"] = content_emb
|
||||
|
||||
prev_entry_child = entry
|
||||
parent_entry={}
|
||||
parent_state["word_len_childs"] = 0
|
||||
parent_state["content_emb"] = ''
|
||||
|
||||
else : ## تست شد : پیش نمی آید
|
||||
print('### no parent for child ####### error data id=', id, ' parent_id : ', parent_id , ' parent_state : ', parent_state["id"] )
|
||||
|
||||
else :
|
||||
|
||||
#if parent_id != 0 :
|
||||
## مواردی هستند که با پدر خود فاصله ایجاد شده است مثل qs918484
|
||||
## فعلا کمک محتوایی براشون نمی کنیم
|
||||
#print('### child withuot parent ####### error data id=', id, ' parent_id : ', parent_id , ' parent_state : ', parent_state["id"] )
|
||||
eid = id
|
||||
content_offset = 'در ' + qanon_title + ' درباره '
|
||||
for hed in path_headings :
|
||||
content_offset += ' ' + hed.strip()
|
||||
content_emb = content
|
||||
|
||||
else :
|
||||
eid = id
|
||||
content_offset = 'در ' + qanon_title + ' درباره '
|
||||
for hed in path_headings :
|
||||
content_offset += ' ' + hed.strip()
|
||||
|
||||
content_emb = content
|
||||
|
||||
|
||||
|
||||
if content_emb :
|
||||
|
||||
payload={
|
||||
'text': content_offset + ' ' + content_emb
|
||||
}
|
||||
response = requests.request("POST", ai_url_vec, headers=HEADERS, json=payload)
|
||||
if response.status_code == 500 :
|
||||
print(response.text)
|
||||
bulk_data = []
|
||||
continue
|
||||
|
||||
resp = json.loads(response.text)
|
||||
data["embeddings"]=resp['result']
|
||||
|
||||
update = False
|
||||
try:
|
||||
if "pos_tags" in data:
|
||||
del data["pos_tags"]
|
||||
if "chunk_tags" in data:
|
||||
del data["chunk_tags"]
|
||||
|
||||
resp = elasticHelper.update_index_doc(update, index_name_o, eid, data)
|
||||
|
||||
except Exception as e:
|
||||
save_error(eid, e)
|
||||
|
||||
except Exception as e:
|
||||
save_error(id, e)
|
||||
|
||||
print("=" * 10, "import_data_embeding finished")
|
||||
|
||||
|
||||
|
||||
|
||||
def import_classification(elasticHelper, ai_url_class, index_name_o = "mj_qa_section_ai") :
|
||||
id = ""
|
||||
body={
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": [
|
||||
{
|
||||
"exists": {
|
||||
"field": "code-ai"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dicIds = {}
|
||||
try:
|
||||
try:
|
||||
list = elasticHelper.es_iterate_all_documents(index_name_o, body)
|
||||
except Exception as e:
|
||||
save_error(0, e)
|
||||
count = 0
|
||||
print('*' * 20 , ' count=', elasticHelper.total)
|
||||
|
||||
for mentry in list:
|
||||
count += 1
|
||||
entry = mentry["source"]
|
||||
|
||||
id = entry.get("id", "")
|
||||
content = entry.get("content", "")
|
||||
data = {}
|
||||
if content :
|
||||
payload={
|
||||
'text':content
|
||||
}
|
||||
response = requests.request("POST", ai_url_class, headers=HEADERS, json=payload)
|
||||
if response.status_code == 500 :
|
||||
print(response.text)
|
||||
continue
|
||||
|
||||
resp = json.loads(response.text)
|
||||
data["code-ai"]=resp['result']
|
||||
|
||||
update = True
|
||||
|
||||
eid = id
|
||||
try:
|
||||
resp = elasticHelper.update_index_doc(update, index_name_o, eid, data)
|
||||
if not update :
|
||||
dicIds[eid] = True
|
||||
|
||||
except Exception as e:
|
||||
save_error(id, e)
|
||||
|
||||
except Exception as e:
|
||||
save_error(id, e)
|
||||
# print("Exception: " + str(e))
|
||||
# print( e)
|
||||
# print("%s -> %.2f " % (id , (counter / total) if total > 0 else 0))
|
||||
|
||||
# try:
|
||||
# print('ts_date:'+ts_date)
|
||||
# except:
|
||||
# print('not definded')
|
||||
|
||||
|
||||
print("=" * 10, " finished")
|
||||
|
||||
|
||||
def isMomSection(other_info, content):
|
||||
if not other_info["full_path"] :
|
||||
return True
|
||||
|
||||
paths = other_info["full_path"].split('>')
|
||||
last_item = paths[len(paths)-1]
|
||||
print(paths)
|
||||
print(last_item)
|
||||
if "ماده" in last_item :
|
||||
return True
|
||||
|
||||
content = content.strip()
|
||||
if re.match(r"^((ضمیمه)|(جدول))\s*\d*$", content):
|
||||
return True
|
||||
|
||||
|
||||
#isMomSection({"full_path":"باب اول>فصل اول>ماده 8"})
|
||||
@@ -1,6 +1,13 @@
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
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.general_functions import *
|
||||
@@ -15,8 +22,28 @@ from s8_Relations_qanon_LWReg import *
|
||||
from s9_Relations_qanon_opinion import *
|
||||
from s10_LawReg_lwphase_Info 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='موضوعات درختی قانون'
|
||||
@@ -29,47 +56,80 @@ from s11_Tanghih_plan_move import *
|
||||
# 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()
|
||||
#insertProjectItems(cursor, projectid)
|
||||
# projectid = insertProejct()
|
||||
# insertProjectItems(cursor, projectid)
|
||||
|
||||
# 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_relations_qanon_lwreg(cursor)
|
||||
import_lawreg_lwphase_info(cursor, elastic, "mj_qa_qanon_temp")
|
||||
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_relations_qanon_opinion(cursor)
|
||||
|
||||
|
||||
# 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)
|
||||
# import_law_section_repair_ref_state(cursor, elastic, "mj_qa_section_temp", "./output/log_s12.txt")
|
||||
# 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')
|
||||
|
||||
cursor.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.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]'
|
||||
cursor.execute(query)
|
||||
|
||||
@@ -48,10 +51,9 @@ def import_lawreg_lwphase_info(cursor):
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
# url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
@@ -173,41 +175,24 @@ def import_lawreg_lwphase_info(cursor):
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' lawreg_lwphase_info , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
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(bulk_data)
|
||||
print(response.text)
|
||||
bulk_data = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
# print(response)
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : eid,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
# print(bulk_count)
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' lawreg_lwphase_info , total='+str(total_count) )
|
||||
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 = []
|
||||
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
# 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')
|
||||
t2= datetime.datetime.now()
|
||||
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,
|
||||
}
|
||||
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||
|
||||
New_ID = json.loads(result.text)["data"][0]["id"]
|
||||
print(str(row["ID"]) + '=' + str(New_ID))
|
||||
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()
|
||||
|
||||
def import_law_section_to_elastic(cursor) :
|
||||
def import_law_section_to_elastic(cursor, elastic, index_name_o) :
|
||||
|
||||
query = '''
|
||||
select
|
||||
@@ -87,7 +87,7 @@ def import_law_section_to_elastic(cursor) :
|
||||
cursor.execute(query)
|
||||
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())
|
||||
|
||||
headers = HEADERS
|
||||
@@ -126,6 +126,8 @@ def import_law_section_to_elastic(cursor) :
|
||||
|
||||
qanon_title = text_normal.normalize_qanon( row.lawTitle )
|
||||
title_type = getTitleType(qanon_title)
|
||||
if(row.ISCORRECTIONLETTER == 1):
|
||||
title_type = 'نامه'
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
@@ -147,9 +149,7 @@ def import_law_section_to_elastic(cursor) :
|
||||
sub_type = row.regulationType
|
||||
sub_type = normalYehKe(sub_type)
|
||||
|
||||
# other_type = 'اصلی'
|
||||
# if(row.ISCORRECTIONLETTER == 1):
|
||||
# other_type = 'اصلاحی'
|
||||
|
||||
|
||||
|
||||
ts_year = ''
|
||||
@@ -238,40 +238,29 @@ def import_law_section_to_elastic(cursor) :
|
||||
|
||||
if len(bulk_data) >= 200:
|
||||
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'])
|
||||
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 = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId )
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_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:
|
||||
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'])
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
|
||||
|
||||
print('=' * 5, 'law_section ===', ', total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId )
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
print('end success import_law_section_to_elastic')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -13,7 +13,7 @@ from app.common.config_base import *
|
||||
from app.common.general_functions import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
def import_opinion_to_elastic(cursor) :
|
||||
def import_opinion_to_elastic(cursor, elastic, index_name_o) :
|
||||
query = """
|
||||
SELECT
|
||||
isnull(o.[ID],0) as ref_id
|
||||
@@ -41,7 +41,7 @@ def import_opinion_to_elastic(cursor) :
|
||||
cursor.execute(query)
|
||||
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())
|
||||
|
||||
headers = HEADERS
|
||||
@@ -163,36 +163,26 @@ def import_opinion_to_elastic(cursor) :
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, 'opinion_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
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 = []
|
||||
break
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
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:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' opinion_to_elastic , total='+str(total_count) )
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
print("end success import_opinion_to_elastic")
|
||||
t2 = datetime.datetime.now()
|
||||
|
||||
@@ -16,7 +16,7 @@ from app.common.config_base import *
|
||||
from app.common.general_functions import *
|
||||
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 = '''
|
||||
select
|
||||
s.ID as sectionId
|
||||
@@ -87,7 +87,7 @@ def import_regulation_section_to_elastic(cursor):
|
||||
cursor.execute(query)
|
||||
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())
|
||||
|
||||
headers = HEADERS
|
||||
@@ -125,7 +125,9 @@ def import_regulation_section_to_elastic(cursor):
|
||||
|
||||
qanon_title = text_normal.normalize_qanon( row.lawTitle )
|
||||
title_type = getTitleType(qanon_title)
|
||||
|
||||
if(row.ISCORRECTIONLETTER == 1):
|
||||
title_type = 'نامه'
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
parentId = '0'
|
||||
@@ -146,11 +148,6 @@ def import_regulation_section_to_elastic(cursor):
|
||||
sub_type = row.regulationType
|
||||
sub_type = normalYehKe(sub_type)
|
||||
|
||||
# other_type = 'اصلی'
|
||||
# if(row.ISCORRECTIONLETTER == 1):
|
||||
# other_type = 'اصلاحی'
|
||||
|
||||
|
||||
ts_year = ''
|
||||
if row.aproveDate :
|
||||
items = row.aproveDate.split("/")
|
||||
@@ -235,39 +232,22 @@ def import_regulation_section_to_elastic(cursor):
|
||||
|
||||
if len(bulk_data) >= 200:
|
||||
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'])
|
||||
|
||||
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 = []
|
||||
break
|
||||
print('=' * 10, ' regulation_section , total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId)
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
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:
|
||||
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'])
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
print('=' * 10, ' regulation_section , total='+str(total_count) , str(i)+ ', id=' + eid , ' , lawid_current =' + lawId )
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
print('end success import_regulation_section_to_elastic')
|
||||
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 = '''
|
||||
SELECT
|
||||
gl1.ID as id,
|
||||
@@ -52,7 +52,7 @@ def import_law_section_update_ref_state(cursor):
|
||||
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())
|
||||
|
||||
headers = HEADERS
|
||||
@@ -148,11 +148,15 @@ def import_law_section_update_ref_state(cursor):
|
||||
|
||||
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
}
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : previd,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
ref_state_array = []
|
||||
previd = eid
|
||||
@@ -163,24 +167,8 @@ def import_law_section_update_ref_state(cursor):
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' law_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||
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 = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
# print(response)
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
@@ -190,17 +178,20 @@ def import_law_section_update_ref_state(cursor):
|
||||
|
||||
if ref_state_array.__len__() > 0 :
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
bulk_data.append(data)
|
||||
# print(bulk_data)
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : previd,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' law_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
# print(response.text)
|
||||
|
||||
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 = '''
|
||||
SELECT
|
||||
gl1.ID as id,
|
||||
@@ -54,7 +54,7 @@ def import_regulation_section_update_ref_state(cursor):
|
||||
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())
|
||||
|
||||
headers = HEADERS
|
||||
@@ -149,11 +149,16 @@ def import_regulation_section_update_ref_state(cursor):
|
||||
|
||||
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
}
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : previd,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
ref_state_array = []
|
||||
previd = eid
|
||||
@@ -164,24 +169,8 @@ def import_regulation_section_update_ref_state(cursor):
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' regulation_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||
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 = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
# print(response)
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
@@ -190,18 +179,22 @@ def import_regulation_section_update_ref_state(cursor):
|
||||
|
||||
if ref_state_array.__len__() > 0 :
|
||||
data={
|
||||
'id' : previd,
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
bulk_data.append(data)
|
||||
# print(bulk_data)
|
||||
'ref_state' : ref_state_array
|
||||
}
|
||||
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : previd,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' regulation_section_update_ref_state , total='+str(total_count) , str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# print(response.text)
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
print('end success import_regulation_section_update_ref_state')
|
||||
t2= datetime.datetime.now()
|
||||
|
||||
@@ -12,7 +12,7 @@ from app.common.config_base import *
|
||||
from app.common.general_functions import *
|
||||
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 = '''
|
||||
SELECT
|
||||
@@ -21,6 +21,8 @@ def import_law_reg_qanon_to_elastic(cursor):
|
||||
--,[F_LWBASETABLEID_LAWTYPE]
|
||||
,l1.[ISLAW] -- قانون
|
||||
,l1.[ISREGULATION] -- مقرره
|
||||
,l1.[ISCORRECTIONLETTER] -- نامه اصلاحی
|
||||
,l1.[ISOPINION] -- آراء
|
||||
,isnull(l1.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
||||
,isnull(l1.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
||||
--,[F_LWBASETABLEID_CLASSIFICATION]
|
||||
@@ -43,14 +45,30 @@ def import_law_reg_qanon_to_elastic(cursor):
|
||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
||||
where l1.ID = l2.id
|
||||
) 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
|
||||
left JOIN cmBasetable cbt ON l1.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
||||
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()
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/add"
|
||||
# url = BASE_URL + "repo/majles/qaqanon/multi/add"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
@@ -81,8 +99,15 @@ def import_law_reg_qanon_to_elastic(cursor):
|
||||
|
||||
|
||||
title = text_normal.normalize_qanon( row.title )
|
||||
title_type = getTitleType(title)
|
||||
|
||||
title_type=''
|
||||
if(row.ISOPINION == 1):
|
||||
title_type=''
|
||||
else:
|
||||
title_type = getTitleType(title)
|
||||
|
||||
if(row.ISCORRECTIONLETTER == 1):
|
||||
title_type = 'نامه'
|
||||
|
||||
eid='qq'+ str(row.Id)
|
||||
|
||||
main_type = ''
|
||||
@@ -90,36 +115,60 @@ def import_law_reg_qanon_to_elastic(cursor):
|
||||
main_type = 'قانون'
|
||||
elif(row.ISREGULATION == 1):
|
||||
main_type = 'مقرره'
|
||||
elif(row.ISOPINION == 1):
|
||||
main_type = 'آراء'
|
||||
|
||||
ts_ref = normalYehKe(row.ts_ref)
|
||||
sub_type = ''
|
||||
if(row.ISLAW == 1):
|
||||
sub_type = row.lawType
|
||||
elif(row.ISREGULATION == 1):
|
||||
sub_type = row.regulationType
|
||||
sub_type = normalYehKe(sub_type)
|
||||
elif(row.ISOPINION == 1):
|
||||
sub_type = row.opinionType
|
||||
if 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 = ''
|
||||
if(row.ISLAW == 1):
|
||||
qanon_number = row.LAWNO
|
||||
elif(row.ISREGULATION == 1):
|
||||
qanon_number = row.RULENO
|
||||
elif(row.ISOPINION == 1):
|
||||
qanon_number = row.opinionNumber
|
||||
|
||||
# other_type = 'اصلی' اصلاحی....
|
||||
# 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 = ''
|
||||
if row.aproveDate :
|
||||
items = row.aproveDate.split("/")
|
||||
if aproveDate :
|
||||
items = aproveDate.split("/")
|
||||
if items.__len__() > 0:
|
||||
ts_year = items[0]
|
||||
|
||||
ts_ref = normalYehKe(row.ts_ref)
|
||||
|
||||
sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی
|
||||
try:
|
||||
sort_date_timestamp = getSortTimestamp(row.aproveDate)
|
||||
sort_date_timestamp = getSortTimestamp(aproveDate)
|
||||
except Exception as e:
|
||||
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_type': title_type,
|
||||
'expire_date': expire_date,
|
||||
'ts_date': row.aproveDate,
|
||||
'ts_date': aproveDate,
|
||||
'ts_year': ts_year,
|
||||
'ts_ref': ts_ref,
|
||||
'qanon_etebar' : qanon_etebar,
|
||||
@@ -148,38 +197,26 @@ def import_law_reg_qanon_to_elastic(cursor):
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' law_reg_qanon_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
|
||||
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 = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_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:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' law_reg_qanon_to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
print('end success law_reg_qanon_to_elastic ')
|
||||
t2= datetime.datetime.now()
|
||||
|
||||
@@ -11,7 +11,7 @@ from app.common.general_functions import *
|
||||
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
|
||||
query = """
|
||||
SELECT
|
||||
@@ -38,7 +38,7 @@ def import_relations_qanon_lwreg(cursor):
|
||||
cursor.execute(query)
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
# url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
@@ -134,16 +134,19 @@ def import_relations_qanon_lwreg(cursor):
|
||||
continue
|
||||
else :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'qanon_relations' : relations
|
||||
'qanon_relations' : relations
|
||||
}
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : prev_eid,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
total_count = total_count+1
|
||||
# if total_count < 2560 :
|
||||
# continue
|
||||
|
||||
bulk_data.append(data)
|
||||
|
||||
prev_eid = eid
|
||||
relations=[]
|
||||
relations.append(relation)
|
||||
@@ -152,24 +155,8 @@ def import_relations_qanon_lwreg(cursor):
|
||||
if len(bulk_data) >= 10:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' relations_qanon_lwreg , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
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 = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
# print(response)
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
@@ -178,33 +165,22 @@ def import_relations_qanon_lwreg(cursor):
|
||||
|
||||
if len(relations) :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'qanon_relations' : relations
|
||||
}
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : prev_eid,
|
||||
'_source' : data
|
||||
}
|
||||
bulk_data.append(data)
|
||||
)
|
||||
|
||||
|
||||
while len(bulk_data) > 0 :
|
||||
|
||||
if len(bulk_data) > 0 :
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' relations_qanon_lwreg , total='+str(total_count))
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
|
||||
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 = pops_data
|
||||
if not bulk_data :
|
||||
break
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
t2= datetime.datetime.now()
|
||||
|
||||
@@ -10,7 +10,7 @@ from app.common.config_base import *
|
||||
from app.common.general_functions import *
|
||||
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
|
||||
query = """
|
||||
SELECT
|
||||
@@ -39,7 +39,7 @@ def import_relations_qanon_opinion(cursor):
|
||||
cursor.execute(query)
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
# url = BASE_URL + "repo/majles/qaqanon/multi/update"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
@@ -138,10 +138,14 @@ def import_relations_qanon_opinion(cursor):
|
||||
continue
|
||||
else :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'opinion_relations' : relations
|
||||
}
|
||||
bulk_data.append(data)
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : prev_eid,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
prev_eid = eid
|
||||
relations=[]
|
||||
@@ -151,25 +155,8 @@ def import_relations_qanon_opinion(cursor):
|
||||
if len(bulk_data) >= 10:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' relations_qanon_opinion , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
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(bulk_data)
|
||||
print(response.text)
|
||||
bulk_data = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
# print(response)
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
@@ -178,32 +165,20 @@ def import_relations_qanon_opinion(cursor):
|
||||
|
||||
if len(relations) > 0 :
|
||||
data={
|
||||
'id' : prev_eid,
|
||||
'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)
|
||||
print('=' * 10, ' relations_qanon_opinion , total='+str(total_count))
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
|
||||
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 = pops_data
|
||||
if not bulk_data :
|
||||
break
|
||||
elastic.updateBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
t2= datetime.datetime.now()
|
||||
|
||||
Reference in New Issue
Block a user