refactor codes and names
This commit is contained in:
@@ -2,6 +2,7 @@ from app.common.normalizer import Normalizer
|
||||
from app.common.tokenizer import *
|
||||
from app.common.jalali import Gregorian,Persian
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
from re import sub
|
||||
import textwrap
|
||||
@@ -1325,6 +1326,27 @@ def extract_excel_fields(file_path: str, fields: list = [], sheet_name: str = No
|
||||
print(f"❌ خطا در خواندن فایل اکسل: {e}")
|
||||
return []
|
||||
|
||||
|
||||
|
||||
def get_files(directory, pattern_file=r"output_(\d+)\.json$"):
|
||||
|
||||
pattern = None
|
||||
if pattern_file :
|
||||
pattern = re.compile(pattern_file)
|
||||
|
||||
max_num = 0
|
||||
list_file = []
|
||||
|
||||
for filename in os.listdir(directory):
|
||||
if pattern :
|
||||
match = pattern.match(filename)
|
||||
if match:
|
||||
list_file.append(directory+"/"+filename)
|
||||
else:
|
||||
list_file.append(directory+"/"+filename)
|
||||
|
||||
return list_file
|
||||
|
||||
# prefix, title = normalHeadingTitle("فصل اول - سیاستها و اصول")
|
||||
# print('prefix :', prefix)
|
||||
# print('title :', title)
|
||||
@@ -9,30 +9,11 @@ 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 getTitleType
|
||||
from app.common.general_functions import getTitleType, get_files
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
def get_files(directory, pattern_file=r"output_(\d+)\.json$"):
|
||||
|
||||
pattern = None
|
||||
if pattern_file :
|
||||
pattern = re.compile(pattern_file)
|
||||
|
||||
max_num = 0
|
||||
list_file = []
|
||||
|
||||
for filename in os.listdir(directory):
|
||||
if pattern :
|
||||
match = pattern.match(filename)
|
||||
if match:
|
||||
list_file.append(directory+"/"+filename)
|
||||
else:
|
||||
list_file.append(directory+"/"+filename)
|
||||
|
||||
return list_file
|
||||
|
||||
|
||||
def parse_and_update_code(file_path, elastic, index_name_o = "mj_qa_section", update_to_elastic=False, by_ai_code = False):
|
||||
try:
|
||||
@@ -375,7 +356,7 @@ def genrate_list_negative(paths=[],list_minues=[]):
|
||||
for path in paths :
|
||||
print('*', 100)
|
||||
print('******** ', path)
|
||||
for file in get_files(path):
|
||||
for file in get_files(path, r"output_(\d+)\.json$"):
|
||||
print(file)
|
||||
list_prccessed_negative_file = parse_and_update_code(file, elastic, "mj_qa_section", False)
|
||||
list_prccessed_negative.extend(list_prccessed_negative_file)
|
||||
@@ -402,7 +383,7 @@ def import_codes_to_elastic(elastic, all_codes, by_ai_code, paths=[], list_minue
|
||||
for path in paths :
|
||||
print('*', 100)
|
||||
print('******** ', path)
|
||||
for file in get_files(path):
|
||||
for file in get_files(path, r"output_(\d+)\.json$"):
|
||||
print(file)
|
||||
if 'data_h100_full' in path : # data_h100_full_1 , ..., data_h100_full_4
|
||||
list_prccessed_negative_file = parse_and_update_multi_code(file, elastic, all_codes, "mj_qa_section", True, by_ai_code)
|
||||
@@ -427,7 +408,7 @@ def parse_notvalid_multi_codes(paths, all_codes=[], file_not_valid="processed_id
|
||||
for path in paths :
|
||||
print('*', 100)
|
||||
print('******** ', path)
|
||||
for file in get_files(path):
|
||||
for file in get_files(path, r"output_(\d+)\.json$"):
|
||||
print(file)
|
||||
data = []
|
||||
with open(file, 'r', encoding="utf8") as f:
|
||||
@@ -471,7 +452,7 @@ def extract_sectionid_in_files(paths, sections=[], file_result="section_id_files
|
||||
for path in paths :
|
||||
print('*', 100)
|
||||
print('******** ', path)
|
||||
for file in get_files(path):
|
||||
for file in get_files(path, r"output_(\d+)\.json$"):
|
||||
print(file)
|
||||
data = []
|
||||
with open(file, 'r', encoding="utf8") as f:
|
||||
|
||||
@@ -115,3 +115,22 @@ col_index = {
|
||||
### --- درج در الاستیک نمی کند update_elastic = False
|
||||
# run_codes_to_elastic_directory( elastic, "./data/tcodes/corrected_majles/not_edit3", "./data/tcodes/corrected_majles/not_edit3/result", all_codes, False, True, col_index, False)
|
||||
# run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit3/result","./data/tcodes/corrected_majles/not_edit3/result_json",all_codes,col_index,True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
col_index = {
|
||||
"section_title" : 0,
|
||||
"ts_date" : 1,
|
||||
"qanon_title" : 2,
|
||||
"code_state" : 3,
|
||||
"code_title" : 4,
|
||||
"row_number" : 5,
|
||||
"qanon_id" : 6,
|
||||
"section_id" : 7,
|
||||
"state_match" : 8,
|
||||
}
|
||||
### --- درج در الاستیک نمی کند update_elastic = False
|
||||
# run_codes_to_elastic_directory( elastic, "./data/tcodes/corrected_majles/not_edit4", "./data/tcodes/corrected_majles/not_edit4/result", all_codes, False, True, col_index, False)
|
||||
run_codes_extract_directory("./data/tcodes/corrected_majles/not_edit4/result","./data/tcodes/corrected_majles/not_edit4/result_json",all_codes,col_index,True)
|
||||
@@ -1,55 +0,0 @@
|
||||
import numbers
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from elasticsearch import Elasticsearch, helpers
|
||||
import json
|
||||
import re
|
||||
import zipfile
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
from app.common.general_functions import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
from app.for_ai.codes_import_from_excel import (
|
||||
run_codes_extract_directory,
|
||||
run_codes_to_elastic_directory,
|
||||
)
|
||||
from app.parvande_qanon.import_qavanin_excels_to_elastic import (
|
||||
import_excel_before_to_elastic,
|
||||
import_excel_after_to_elastic,
|
||||
import_excel_tasmimat_to_elastic,
|
||||
)
|
||||
from app.parvande_qanon.repair_qa_qanon_for_map_new import *
|
||||
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
|
||||
load_dotenv(dotenv_path="config.env")
|
||||
|
||||
host = os.getenv("HOST_160")
|
||||
password = os.getenv("HOST_160_PASS")
|
||||
|
||||
# host = os.getenv("HOST_112")
|
||||
# password = os.getenv("HOST_112_PASS")
|
||||
|
||||
# host = os.getenv("HOST_H102")
|
||||
# password = os.getenv("HOST_H102_PASS")
|
||||
# print( "---------------->>>>>>>>>>>>>>>", host )
|
||||
|
||||
# host=os.getenv('HOST_113')
|
||||
# password=os.getenv('HOST_113_PASS')
|
||||
|
||||
|
||||
print(".... majles_codes_update_steps ......", host)
|
||||
|
||||
path_base_map = "G:/Project2/gateway_php/repo/_other/"
|
||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
file_path = r'C:\Users\TAVASI-3\Desktop\init_mahdi\project\dataParsers\data\FLC\cleaned\temp.json'
|
||||
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
|
||||
import re
|
||||
matches = re.findall(r'persian', text)
|
||||
print("تعداد دقیق:", len(matches))
|
||||
@@ -1,168 +0,0 @@
|
||||
import mariadb
|
||||
from dotenv import load_dotenv
|
||||
import os
|
||||
import datetime
|
||||
import json
|
||||
import uuid
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def import_to_gn_tree_elastic(cursor, elastic, project_id, project_title, index_name_o) :
|
||||
|
||||
query = f"""
|
||||
SELECT id, title, parent, child_order, meta, tags from tlist.tl_subjects
|
||||
where project_id={project_id}
|
||||
ORDER BY parent, child_order
|
||||
"""
|
||||
# print('-'*10)
|
||||
# print(query)
|
||||
# print('-'*10)
|
||||
cursor.execute(query)
|
||||
|
||||
parent_nodes = {}
|
||||
bulk_data=[]
|
||||
total_count = 0
|
||||
|
||||
t1 = datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i = i + 1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
id = row[0]
|
||||
# eid = uuid.uuid4().hex[:8]
|
||||
eid = 'gnt'+str(id).zfill(5)
|
||||
title = row[1].strip()
|
||||
parent = row[2]
|
||||
parent_id = 0
|
||||
if parent != 0 :
|
||||
parent_id = 'gnt'+str(parent).zfill(5)
|
||||
child_order = row[3]
|
||||
meta = row[4]
|
||||
tags = row[5]
|
||||
|
||||
|
||||
meta_info = {}
|
||||
if meta :
|
||||
meta_info["id1"] = str(meta)
|
||||
|
||||
tags_list = []
|
||||
if tags :
|
||||
for tt in tags.strip().split(',') :
|
||||
if tt and not tt in tags_list :
|
||||
tags_list.append(tt)
|
||||
|
||||
|
||||
main_type_key = "tree"+str(project_id)
|
||||
data={
|
||||
"id" : eid,
|
||||
"version_key" : "base_1",
|
||||
"main_type_key" : main_type_key,
|
||||
"main_type" : project_title,
|
||||
# "group_key" : "",
|
||||
"title" : title,
|
||||
"parent_id" : parent_id,
|
||||
"child_order" : child_order,
|
||||
"tags" : tags_list,
|
||||
"meta_info" : meta_info
|
||||
}
|
||||
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, 'to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : eid,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' to_elastic , total='+str(total_count) )
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
print("end success import_to_elastic")
|
||||
t2 = datetime.datetime.now()
|
||||
print(t2 - t1)
|
||||
|
||||
|
||||
|
||||
load_dotenv(dotenv_path="config.env")
|
||||
|
||||
host = os.getenv("HOST_160_LOCAL")
|
||||
password = os.getenv("HOST_160_PASS")
|
||||
|
||||
# print(host)
|
||||
# print(password)
|
||||
|
||||
|
||||
path_base_map = "/home/sabr/back_new/elastic_backend/app/schemas/mappings/"
|
||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||
|
||||
|
||||
config_env = load_dotenv(dotenv_path="./config.env")
|
||||
MYSQL_username = os.getenv("MYSQL_username")
|
||||
MYSQL_root_password = os.getenv("MYSQL_root_password")
|
||||
MYSQL_port = os.getenv("MYSQL_port")
|
||||
MYSQL_host = os.getenv("MYSQL_import_host")
|
||||
cnx = mariadb.connect(user="root", password=MYSQL_root_password, host=MYSQL_host)
|
||||
cursor = cnx.cursor()
|
||||
|
||||
|
||||
query = "select id, title from tlist.tl_projects"
|
||||
cursor.execute(query)
|
||||
list_projects=[]
|
||||
while 1 :
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
|
||||
pid = row[0] # "id"
|
||||
title = row[1] # "title"
|
||||
# print(title)
|
||||
|
||||
# پلانهای استفاده نشده در مجلس
|
||||
if pid >= 100 and pid <= 200 :
|
||||
continue
|
||||
|
||||
# موضوعات درختی قدیم که دیگه جایگزین با 6 شد
|
||||
if pid == 1 :
|
||||
continue
|
||||
|
||||
list_projects.append({
|
||||
"id" : pid,
|
||||
"title" : title
|
||||
})
|
||||
|
||||
|
||||
|
||||
for item in list_projects :
|
||||
print('*'*100)
|
||||
print(item)
|
||||
import_to_gn_tree_elastic( cursor, elastic, item["id"], item["title"],"gn_tree")
|
||||
|
||||
|
||||
cursor.close()
|
||||
@@ -11,7 +11,7 @@ import time
|
||||
from tqdm import tqdm
|
||||
from pydantic import BaseModel
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
@@ -20,7 +20,7 @@ from app.common.text_normalizer import TextNormalizer
|
||||
from app.common.data_helper import DataHelper
|
||||
|
||||
|
||||
from app.majles_options import *
|
||||
# from app.majles.majles_options import *
|
||||
|
||||
|
||||
class OutputLabels(BaseModel):
|
||||
@@ -41,7 +41,7 @@ class OutputLabels(BaseModel):
|
||||
exception: Clause | None
|
||||
|
||||
|
||||
load_dotenv(dotenv_path=r"D:\init_mahdi\dataParsers\config.env")
|
||||
load_dotenv(dotenv_path="config.env")
|
||||
|
||||
host = os.getenv("HOST_160")
|
||||
password = os.getenv("HOST_160_PASS")
|
||||
@@ -49,8 +49,9 @@ password = os.getenv("HOST_160_PASS")
|
||||
# host = os.getenv("HOST_112")
|
||||
# password = os.getenv("HOST_112_PASS")
|
||||
|
||||
# print(host)
|
||||
# print(password)
|
||||
|
||||
# host = os.getenv("HOST_H101")
|
||||
# password = os.getenv("HOST_H101_PASS")
|
||||
|
||||
|
||||
# path_base_map = (
|
||||
@@ -542,22 +543,22 @@ if __name__ == "__main__":
|
||||
# log_file.close()
|
||||
|
||||
# ### ----------------------------------------------
|
||||
data_key = "rules_labels"
|
||||
# label_object
|
||||
index_name = "mj_qa_rule"
|
||||
json_path = r"D:\init_mahdi\dataParsers\merge_labels.json"
|
||||
extract_json_context_id_rules_labels(
|
||||
elastic=elastic, index_name=index_name, json_path=json_path
|
||||
)
|
||||
# data_key = "rules_labels"
|
||||
# # label_object
|
||||
# index_name = "mj_qa_rule"
|
||||
# json_path = r"D:\init_mahdi\dataParsers\merge_labels.json"
|
||||
# extract_json_context_id_rules_labels(
|
||||
# elastic=elastic, index_name=index_name, json_path=json_path
|
||||
# )
|
||||
|
||||
# ### ----------------------------------------------
|
||||
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_context", "mj_qa_context")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_rule", "mj_qa_rule")
|
||||
|
||||
# mapping_file_path = "G:/\Project2/_back/_to_majles/14041022/src/repo/_other/majles/mj_qa_context.json"
|
||||
# mapping_file_path = "G:/\Project2/tavasi_160/src/repo/_other/majles/mj_qa_context.json"
|
||||
# elastic.restorFileToElastic2('G:/Project2/102_gpu/mj_qa_context.zip', 'mj_qa_context', 'majles', False, 'mj_qa_context', mapping_file_path)
|
||||
|
||||
# mapping_file_path = "G:/\Project2/_back/_to_majles/14041022/src/repo/_other/majles/mj_qa_rule.json"
|
||||
# mapping_file_path = "G:/\Project2/tavasi_160/src/repo/_other/majles/mj_qa_rule.json"
|
||||
# elastic.restorFileToElastic2('G:/Project2/102_gpu/mj_qa_rule.zip', 'mj_qa_rule', 'majles', False, 'mj_qa_rule', mapping_file_path)
|
||||
|
||||
# ### ----------------------------------------------
|
||||
@@ -8,7 +8,7 @@ import pandas as pd
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
@@ -16,7 +16,7 @@ from app.common.general_functions import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
|
||||
from app.majles_options import *
|
||||
from app.majles.majles_options import *
|
||||
|
||||
|
||||
load_dotenv(dotenv_path="config.env")
|
||||
+146
@@ -249,6 +249,9 @@ def import_content_opinion_to_qaqanon(elastic, path_file, index_name_o):
|
||||
|
||||
qanon_id = entry.get("qanon_id", "")
|
||||
eid = qanon_id
|
||||
|
||||
# if not qanon_id == "qq296834" :
|
||||
# continue
|
||||
|
||||
ref_id = entry.get("ref_id", "")
|
||||
ref_key = entry.get("ref_key", "")
|
||||
@@ -325,6 +328,7 @@ def import_content_opinion_to_qaqanon(elastic, path_file, index_name_o):
|
||||
|
||||
if html: # ساختن دوباره و بهتر
|
||||
content = html_to_text_preserve_lines(html)
|
||||
content = text_normal.normalize_qanon(content)
|
||||
content_len = len(content)
|
||||
|
||||
data["content"] = content
|
||||
@@ -371,3 +375,145 @@ def import_content_opinion_to_qaqanon(elastic, path_file, index_name_o):
|
||||
|
||||
except Exception as e:
|
||||
print("Exception: " + str(e))
|
||||
|
||||
def extract_content_opinion_to_qaqanon(elastic, path_file, index_name_o, path_out = "./data/"):
|
||||
|
||||
bulk_list = []
|
||||
bulk_list_import = []
|
||||
pack_size = 100
|
||||
|
||||
count = 0
|
||||
id = ""
|
||||
try:
|
||||
|
||||
try:
|
||||
list_ = elastic.iterateJsonFile(path_file, True)
|
||||
except Exception as e:
|
||||
print("Exception es_iterate_all_documents : " + str(e))
|
||||
|
||||
list_items = list(list_)
|
||||
total = elastic.total
|
||||
print("*" * 20, " count=", elastic.total)
|
||||
total_count = 0
|
||||
percent_prev = 0
|
||||
|
||||
|
||||
for mentry in list_items:
|
||||
count += 1
|
||||
entry = mentry["source"]
|
||||
|
||||
id = entry.get("id", "")
|
||||
|
||||
qanon_id = entry.get("qanon_id", "")
|
||||
eid = qanon_id
|
||||
|
||||
percent = int((count / len(list_items)) * 100)
|
||||
if percent != percent_prev:
|
||||
print("progress -> %.2f %%" % percent)
|
||||
percent_prev = percent
|
||||
|
||||
# if not qanon_id == "qq296834" :
|
||||
# continue
|
||||
|
||||
ref_id = entry.get("ref_id", "")
|
||||
ref_key = entry.get("ref_key", "")
|
||||
title_popular = entry.get("title_popular", "")
|
||||
|
||||
title = entry.get("title", "")
|
||||
title_type = entry.get("title_type", "")
|
||||
ts_year = entry.get("ts_year", "")
|
||||
ts_ref = entry.get("ts_ref", "")
|
||||
sub_type = entry.get("sub_type", "")
|
||||
qanon_etebar = entry.get("qanon_etebar", "")
|
||||
sort_date_timestamp = entry.get("sort_date_timestamp", "")
|
||||
|
||||
ts_date = entry.get("ts_date", "")
|
||||
ts_date, err_msg = convert_persian_date(ts_date)
|
||||
|
||||
expire_date = entry.get("expire_date", "")
|
||||
expire_date, err_msg = convert_persian_date(expire_date)
|
||||
|
||||
aproveDate = entry.get("aproveDate", "")
|
||||
aproveDate, err_msg = convert_persian_date(aproveDate)
|
||||
|
||||
content = entry.get("content", "")
|
||||
content = text_normal.normalize_qanon(content)
|
||||
|
||||
html = entry.get("html", "")
|
||||
html = text_normal.yeke_normal(html)
|
||||
|
||||
content_len = entry.get("content_len", "")
|
||||
|
||||
eblagh_number = validate_value(entry.get("eblagh_number", ""))
|
||||
eblagh_date = entry.get("eblagh_date", "")
|
||||
eblagh_date, err_msg = convert_persian_date(eblagh_date)
|
||||
|
||||
eblagh = {}
|
||||
if eblagh_number or eblagh_date:
|
||||
eblagh["number"] = eblagh_number
|
||||
if eblagh_date:
|
||||
eblagh["date"] = eblagh_date
|
||||
|
||||
item = {}
|
||||
is_update = True
|
||||
try:
|
||||
item = elastic.get_document(index_name_o, eid)
|
||||
except:
|
||||
is_update = False
|
||||
|
||||
data = {}
|
||||
if not is_update:
|
||||
main_type = "آراء"
|
||||
data = {
|
||||
"id": eid,
|
||||
"ref_id": ref_id,
|
||||
"ref_key": ref_key,
|
||||
"main_type": main_type,
|
||||
"sub_type": sub_type,
|
||||
"title": title,
|
||||
"ts_year": ts_year,
|
||||
"ts_ref": ts_ref,
|
||||
"qanon_etebar": qanon_etebar,
|
||||
"sort_date_timestamp": sort_date_timestamp, # created from repairQanon.getSortTimestamp
|
||||
}
|
||||
if title_type:
|
||||
data["title_type"] = title_type
|
||||
if title_popular:
|
||||
data["title_popular"] = title_popular
|
||||
|
||||
if ts_date:
|
||||
data["ts_date"] = ts_date
|
||||
if expire_date:
|
||||
data["expire_date"] = expire_date
|
||||
if aproveDate:
|
||||
data["exec_date"] = aproveDate
|
||||
|
||||
if html: # ساختن دوباره و بهتر
|
||||
content = html_to_text_preserve_lines(html)
|
||||
content = text_normal.normalize_qanon(content)
|
||||
content_len = len(content)
|
||||
|
||||
data["content"] = content
|
||||
|
||||
if html and isNeedHtml(html):
|
||||
data["html"] = html
|
||||
|
||||
data["content_len"] = content_len
|
||||
if eblagh:
|
||||
data["eblagh"] = eblagh
|
||||
|
||||
if is_update:
|
||||
bulk_list.append({"id": eid, "_source": data})
|
||||
else:
|
||||
bulk_list_import.append({"id": eid, "_source": data})
|
||||
|
||||
file1 = path_out + "1_opinion_update.json"
|
||||
with open(file1, 'w', encoding='utf8') as f :
|
||||
json.dump(bulk_list, f, ensure_ascii=False, indent=4)
|
||||
|
||||
file1 = path_out + "1_opinion_import.json"
|
||||
with open(file1, 'w', encoding='utf8') as f :
|
||||
json.dump(bulk_list_import, f, ensure_ascii=False, indent=4)
|
||||
|
||||
except Exception as e:
|
||||
print("Exception: " + str(e))
|
||||
@@ -3,7 +3,7 @@ from dotenv import load_dotenv
|
||||
|
||||
|
||||
import sys
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
@@ -8,18 +8,18 @@ import zipfile
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
from app.common.general_functions import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
from app.parvande_qanon.import_qavanin_excels_to_elastic import (
|
||||
from app.parvande_qanon.s2_import_qavanin_excels_to_elastic import (
|
||||
import_excel_before_to_elastic,
|
||||
import_excel_after_to_elastic,
|
||||
import_excel_tasmimat_to_elastic,
|
||||
)
|
||||
from app.parvande_qanon.repair_qa_qanon_for_map_new import *
|
||||
from app.majles.repair_qa_qanon_for_map_new import *
|
||||
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
@@ -29,12 +29,12 @@ 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_112")
|
||||
password = os.getenv("HOST_112_PASS")
|
||||
|
||||
|
||||
host = os.getenv("HOST_H102")
|
||||
password = os.getenv("HOST_H102_PASS")
|
||||
# host = os.getenv("HOST_H102")
|
||||
# password = os.getenv("HOST_H102_PASS")
|
||||
# print( "---------------->>>>>>>>>>>>>>>", host )
|
||||
|
||||
# host=os.getenv('HOST_113')
|
||||
@@ -230,6 +230,10 @@ file_path = "G:/Project2/160_dotic/mj_mashruh.zip"
|
||||
file_path = 'G:/Project2/160_dotic/dotic_14040824/mj_qa_opinion_doctic_14040824.zip'
|
||||
# import_content_opinion_to_qaqanon(elastic, file_path, "mj_qa_qanon" )
|
||||
|
||||
### ---موقت : یکبار
|
||||
### بخاطر خطای داده در سرور مجلس
|
||||
# extract_content_opinion_to_qaqanon(elastic, file_path, "mj_qa_qanon", 'G:/Project2/160_dotic/dotic_14040824/extract/' )
|
||||
|
||||
|
||||
# # -------------------------------------
|
||||
# # ----- انتقال داده های مشروح مذاکرات به فهرست همه قوانین
|
||||
@@ -367,8 +371,6 @@ file_tasmim = "G:/Project2/160_dotic/duplicate_tasmim.json"
|
||||
# elastic.backupIndexToZipfile("G:/Project2/102_gpu", "mj_qa_section_rule", "mj_qa_section_rule")
|
||||
|
||||
|
||||
|
||||
|
||||
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_mashruh", "mj_mashruh")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/160_dotic", "mj_qa_section", "mj_qa_section")
|
||||
|
||||
@@ -1,349 +0,0 @@
|
||||
type_count = [
|
||||
{
|
||||
"key": "جلسه علمی",
|
||||
"doc_count": 7332
|
||||
},
|
||||
{
|
||||
"key": "منبر",
|
||||
"doc_count": 3970
|
||||
},
|
||||
{
|
||||
"key": "درس خارج",
|
||||
"doc_count": 2450
|
||||
},
|
||||
{
|
||||
"key": "تدریس",
|
||||
"doc_count": 1401
|
||||
},
|
||||
{
|
||||
"key": "سخنرانی",
|
||||
"doc_count": 1221
|
||||
},
|
||||
{
|
||||
"key": "-",
|
||||
"doc_count": 992
|
||||
},
|
||||
{
|
||||
"key": "مشاوره",
|
||||
"doc_count": 858
|
||||
},
|
||||
{
|
||||
"key": "مدیریت",
|
||||
"doc_count": 652
|
||||
},
|
||||
{
|
||||
"key": "مصاحبه",
|
||||
"doc_count": 628
|
||||
},
|
||||
{
|
||||
"key": "مباحثه و گفتگو",
|
||||
"doc_count": 587
|
||||
},
|
||||
{
|
||||
"key": "جزوه",
|
||||
"doc_count": 583
|
||||
},
|
||||
{
|
||||
"key": "مناظره و گفتگو",
|
||||
"doc_count": 496
|
||||
},
|
||||
{
|
||||
"key": "گزارش",
|
||||
"doc_count": 395
|
||||
},
|
||||
{
|
||||
"key": "--",
|
||||
"doc_count": 250
|
||||
},
|
||||
{
|
||||
"key": "جدول",
|
||||
"doc_count": 208
|
||||
},
|
||||
{
|
||||
"key": "کتاب",
|
||||
"doc_count": 173
|
||||
},
|
||||
{
|
||||
"key": "صورت جلسه",
|
||||
"doc_count": 126
|
||||
},
|
||||
{
|
||||
"key": "فهرست",
|
||||
"doc_count": 124
|
||||
},
|
||||
{
|
||||
"key": "ارائه",
|
||||
"doc_count": 90
|
||||
},
|
||||
{
|
||||
"key": "بازدید (دیدار)",
|
||||
"doc_count": 83
|
||||
},
|
||||
{
|
||||
"key": "مقاله",
|
||||
"doc_count": 81
|
||||
},
|
||||
{
|
||||
"key": "طرح",
|
||||
"doc_count": 74
|
||||
},
|
||||
{
|
||||
"key": "کلیپ",
|
||||
"doc_count": 68
|
||||
},
|
||||
{
|
||||
"key": "گزارش رصد",
|
||||
"doc_count": 64
|
||||
},
|
||||
{
|
||||
"key": "نامه",
|
||||
"doc_count": 48
|
||||
},
|
||||
{
|
||||
"key": "نمودار",
|
||||
"doc_count": 45
|
||||
},
|
||||
{
|
||||
"key": "آیین نامه",
|
||||
"doc_count": 36
|
||||
},
|
||||
{
|
||||
"key": "تقریر",
|
||||
"doc_count": 35
|
||||
},
|
||||
{
|
||||
"key": "خلاصه",
|
||||
"doc_count": 25
|
||||
},
|
||||
{
|
||||
"key": "پیش نویس",
|
||||
"doc_count": 25
|
||||
},
|
||||
{
|
||||
"key": "نقد",
|
||||
"doc_count": 23
|
||||
},
|
||||
{
|
||||
"key": "چکیده",
|
||||
"doc_count": 16
|
||||
},
|
||||
{
|
||||
"key": "یادبود",
|
||||
"doc_count": 13
|
||||
},
|
||||
{
|
||||
"key": "فرم",
|
||||
"doc_count": 12
|
||||
},
|
||||
{
|
||||
"key": "فرم فیش",
|
||||
"doc_count": 11
|
||||
},
|
||||
{
|
||||
"key": "مناجات",
|
||||
"doc_count": 10
|
||||
},
|
||||
{
|
||||
"key": "دعا و مناجات",
|
||||
"doc_count": 8
|
||||
},
|
||||
{
|
||||
"key": "فیش",
|
||||
"doc_count": 6
|
||||
},
|
||||
{
|
||||
"key": "پرسش و پاسخ",
|
||||
"doc_count": 6
|
||||
},
|
||||
{
|
||||
"key": "بیانیه",
|
||||
"doc_count": 5
|
||||
},
|
||||
{
|
||||
"key": "اجلاسیه",
|
||||
"doc_count": 4
|
||||
},
|
||||
{
|
||||
"key": "پایان نامه",
|
||||
"doc_count": 4
|
||||
},
|
||||
{
|
||||
"key": "",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "آئین نامه",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "رزومه",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "قرارداد",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "مصوبه",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "نمونه سوال",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "همایش",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "پژوهش",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "چارت",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "کنفرانس",
|
||||
"doc_count": 3
|
||||
},
|
||||
{
|
||||
"key": "تلخیص",
|
||||
"doc_count": 2
|
||||
},
|
||||
{
|
||||
"key": "قرائت زیارت",
|
||||
"doc_count": 2
|
||||
},
|
||||
{
|
||||
"key": "لیست",
|
||||
"doc_count": 2
|
||||
},{
|
||||
"key": "متن جلسه",
|
||||
"doc_count": 2
|
||||
},
|
||||
{
|
||||
"key": "مستند تلوزیونی",
|
||||
"doc_count": 2
|
||||
},
|
||||
{
|
||||
"key": "نشست علمی",
|
||||
"doc_count": 2
|
||||
},
|
||||
{
|
||||
"key": "کتاب داخلی",
|
||||
"doc_count": 2
|
||||
},
|
||||
{
|
||||
"key": "گزارش جلسه",
|
||||
"doc_count": 2
|
||||
},
|
||||
{
|
||||
"key": "برنامه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "بروشور",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "بزرگداشت",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "جزو",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "خطبه عقد(دائم)",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "روضه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "زندگی نامه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "زیارتنامه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "سائر",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "سالگرد",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "سایر",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "طرج",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "عقد",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "ماتریس",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "مدل",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "مراحل دستیابی و به کارگیری الگوی پیشرفت اسلامی ـ ",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "مقالات",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "مقاله و ارائه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "نماه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "نمایه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "هرم",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "پرسشنامه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "پروژه",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "پیش نشست",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "کاربرگ",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "کتاب سایت",
|
||||
"doc_count": 1
|
||||
},
|
||||
{
|
||||
"key": "کمیسیون خبرگان",
|
||||
"doc_count": 1
|
||||
}
|
||||
]
|
||||
@@ -1,160 +0,0 @@
|
||||
import traceback, os, orjson
|
||||
import pandas as pd
|
||||
from pathlib import Path
|
||||
from dataParsers.app.common.elastic_helper import ElasticHelper
|
||||
from dotenv import load_dotenv
|
||||
|
||||
|
||||
def load_orjson(path: str | Path):
|
||||
path = Path(path)
|
||||
with path.open("rb") as f: # باید باینری باز بشه برای orjson
|
||||
return orjson.loads(f.read())
|
||||
|
||||
|
||||
def save_orjson(path, data):
|
||||
with open(path, "wb") as f:
|
||||
f.write(
|
||||
orjson.dumps(data, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS)
|
||||
)
|
||||
|
||||
|
||||
def extract_excel_fields(file_path: str, fields: list = [], sheet_name: str = None):
|
||||
"""
|
||||
فایل اکسل را باز کرده و فقط فیلدهای خواستهشده را بهصورت لیست از دیکشنریها برمیگرداند.
|
||||
|
||||
:param file_path: مسیر فایل اکسل (.xlsx یا .xls)
|
||||
:param fields: لیست نام ستونهایی که باید خوانده شوند
|
||||
:return: لیستی از دیکشنریها شامل دادههای ستونهای انتخابشده
|
||||
"""
|
||||
try:
|
||||
# خواندن فایل
|
||||
df = pd.read_excel(file_path, sheet_name=sheet_name)
|
||||
df.columns = df.columns.map(str)
|
||||
if len(fields) > 0:
|
||||
|
||||
missing = [f for f in fields if f not in df.columns]
|
||||
if missing:
|
||||
print(f"⚠️ This columns mot found in file {missing}")
|
||||
|
||||
# for i in df.columns:
|
||||
# print(f'-field ->{i}<-')
|
||||
|
||||
df = df[[f for f in fields if f in df.columns]]
|
||||
|
||||
# تبدیل به لیست از دیکشنریها
|
||||
data = df.to_dict(orient="records")
|
||||
return data
|
||||
except Exception as e:
|
||||
print(f"❌ خطا در خواندن فایل اکسل: {e}")
|
||||
return []
|
||||
|
||||
|
||||
def save_excel(file_path: str, data: list):
|
||||
"""ذخیرهی دادهها در فایل اکسل جدید"""
|
||||
try:
|
||||
df = pd.DataFrame(data)
|
||||
df.to_excel(file_path, index=False)
|
||||
print(f"✅ فایل با موفقیت ذخیره شد: {file_path}")
|
||||
except Exception as e:
|
||||
print(f"❌ خطا در ذخیره فایل اکسل: {e}")
|
||||
|
||||
|
||||
def convert_data(item):
|
||||
_id = "gnp" + str(item["id"])
|
||||
tree_label = item["person_title"]
|
||||
title = item["title"]
|
||||
|
||||
papa_id = item["papa_id"]
|
||||
if papa_id == 0:
|
||||
parent_id = str(0)
|
||||
else:
|
||||
parent_id = "gnp" + str(papa_id)
|
||||
|
||||
child_order = item["order"]
|
||||
|
||||
return {
|
||||
"id": _id, # "gnt01741"
|
||||
"version_key": "base_1",
|
||||
"tree_key": "tree1",
|
||||
"tree_label": tree_label, # "فهرست موضوعات مسائل و پاسخها",
|
||||
"main_type": "tree",
|
||||
"title": title, # "پیامدهای روبنایی",
|
||||
"parent_id": parent_id,
|
||||
"child_order": child_order,
|
||||
"tags": [],
|
||||
"meta_info": {},
|
||||
}
|
||||
|
||||
|
||||
load_dotenv()
|
||||
es_pass = os.getenv("ES_PASSWORD")
|
||||
es_url = os.getenv("ES_URL")
|
||||
es_user = os.getenv("ES_USER_NAME")
|
||||
es_index_name = os.getenv("GNP_TREE_INDEX_NAME")
|
||||
|
||||
es_helper = ElasticHelper(es_pass=es_pass, es_url=es_url, es_user=es_user)
|
||||
|
||||
if __name__ == "__main__":
|
||||
file_path = r"D:\init_mahdi\dataParsers\041106_لیست تمام موضوعات.xlsx"
|
||||
data_excel = extract_excel_fields(file_path, sheet_name="Sheet1")
|
||||
|
||||
print(f'data_excel {len(data_excel)}')
|
||||
try:
|
||||
f_data = []
|
||||
for i in data_excel:
|
||||
f_data.append(convert_data(i))
|
||||
except Exception as e:
|
||||
print(
|
||||
f"*************",
|
||||
)
|
||||
traceback.print_exc()
|
||||
|
||||
print(f'f_data {len(f_data)}')
|
||||
|
||||
output_path = r"D:\init_mahdi\dataParsers\041106_لیست تمام موضوعات.json"
|
||||
save_orjson(path=output_path, data=f_data)
|
||||
|
||||
|
||||
bulk_data=[]
|
||||
index_name_o = es_index_name
|
||||
elastic = es_helper
|
||||
total_count = 0
|
||||
|
||||
data_list = f_data
|
||||
|
||||
i = 0
|
||||
for data in data_list :
|
||||
eid = data["id"]
|
||||
i = i + 1
|
||||
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, 'to_elastic , total='+str(total_count) , str(i)+ ', id=' + eid )
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
bulk_data.append(
|
||||
{
|
||||
'_id' : eid,
|
||||
'_source' : data
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ' to_elastic , total='+str(total_count) )
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
print("end success import_to_elastic")
|
||||
# for i in f_data:
|
||||
# es_res = es_helper.update_index_doc(
|
||||
# is_update_state=False,
|
||||
# index_name_o=es_index_name,
|
||||
# eid=i["id"],
|
||||
# data=i,
|
||||
# )
|
||||
|
||||
# python -m dataParsers.app.monir.gnp_tree
|
||||
@@ -8,7 +8,7 @@ import pandas as pd
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
@@ -16,7 +16,7 @@ from app.common.general_functions import *
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
|
||||
|
||||
from app.monir_options import (
|
||||
from app.monir.monir_options import (
|
||||
get_public_options,
|
||||
get_monir_options
|
||||
)
|
||||
@@ -24,10 +24,6 @@ from app.monir_options import (
|
||||
|
||||
load_dotenv(dotenv_path="config.env")
|
||||
|
||||
# host = os.getenv("HOST_160")
|
||||
# host = os.getenv("HOST_160_LOCAL")
|
||||
# password = os.getenv("HOST_160_PASS")
|
||||
|
||||
host = os.getenv("HOST_60")
|
||||
password = os.getenv("HOST_60_PASS")
|
||||
|
||||
@@ -527,15 +523,22 @@ if __name__ == "__main__":
|
||||
|
||||
###### -------------- gn_option -----------------------------
|
||||
|
||||
# import_option_base_list(elastic, "gn_option")
|
||||
|
||||
# import_option_base_list(elastic, "gn_option")
|
||||
# import_option_ostan_shahr(elastic, "gn_option")
|
||||
|
||||
|
||||
###### -------------- -----------------------------
|
||||
|
||||
# elastic.backupIndexToZipfile("G:/Project2/111", "mn_sanad_temp", "mn_sanad")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/111", "mn_steps_temp", "mn_steps")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/111", "gn_calendar", "gn_calendar")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "mn_sanad_temp", "mn_sanad")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "mn_steps_temp", "mn_steps")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "gn_calendar", "gn_calendar")
|
||||
|
||||
###### -------------- -----------------------------
|
||||
|
||||
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "gn_tree", "gn_tree")
|
||||
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "gn_option", "gn_option")
|
||||
|
||||
|
||||
# elastic.backupIndexToZipfile("G:/Project2/133_monir", "mn_voice", "mn_voice")
|
||||
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
import numbers
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
from elasticsearch import Elasticsearch, helpers
|
||||
from elasticsearch.helpers import scan
|
||||
import json
|
||||
import re
|
||||
import time, traceback, uuid, orjson, jdatetime, re
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../..")))
|
||||
|
||||
from app.common.text_normalizer import TextNormalizer
|
||||
from app.common.general_functions import *
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
|
||||
|
||||
|
||||
|
||||
text_normal = TextNormalizer()
|
||||
|
||||
|
||||
load_dotenv(dotenv_path='config.env')
|
||||
|
||||
host=os.getenv('HOST_60')
|
||||
password=os.getenv('HOST_60_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)
|
||||
|
||||
|
||||
index_name_o = "mn_voice"
|
||||
path_files = "app/../data/monir/spr_v1/farhangestan-output"
|
||||
|
||||
bulk_data = []
|
||||
total_count = 0
|
||||
files = get_files(path_files, r"(\d+)\.json$")
|
||||
# files = get_files(path_files)
|
||||
|
||||
for file in files :
|
||||
print(file)
|
||||
|
||||
data = {}
|
||||
try :
|
||||
|
||||
with open(file, "r", encoding="utf8") as f:
|
||||
data = json.load(f)
|
||||
|
||||
eid = data["_id"]
|
||||
|
||||
try:
|
||||
res = elastic.get_document(index_name_o, eid)
|
||||
source = res["_source"]
|
||||
continue
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
sound_files = data["sound_files"]
|
||||
|
||||
sound_link = sound_files[0]["link"]
|
||||
sound_title = sound_files[0]["title"]
|
||||
|
||||
author = data["author"]
|
||||
branch = data["branch"]
|
||||
|
||||
|
||||
title = data["title"]
|
||||
begin_date = data["begin_date"]
|
||||
begin_year = data["begin_year"]
|
||||
meet_code = data["meet_code"]
|
||||
meet_no = data["meet_no"]
|
||||
person_code = data["person_code"]
|
||||
city = data["city"]
|
||||
place = data["place"]
|
||||
_format = data["format"]
|
||||
|
||||
words = []
|
||||
transcript = data["transcript"]
|
||||
content = ""
|
||||
if transcript :
|
||||
content = transcript[0]["full_text"]
|
||||
words = transcript[0]["words"]
|
||||
else :
|
||||
if "content" in data :
|
||||
content = data["content"]
|
||||
|
||||
if "words_align" in data :
|
||||
words = data["words_align"]
|
||||
|
||||
content = text_normal.normalize_qanon(content)
|
||||
content = content.strip().strip('\r\t\n')
|
||||
|
||||
word_times = []
|
||||
for w in words :
|
||||
word_times.append(w["start"])
|
||||
|
||||
|
||||
data_item = {
|
||||
"id": eid,
|
||||
"title": title,
|
||||
"author": author,
|
||||
"branch": branch,
|
||||
"begin_date": begin_date,
|
||||
"meet_code": meet_code,
|
||||
"meet_no": meet_no,
|
||||
"person_code": person_code,
|
||||
"city": city,
|
||||
"place": place,
|
||||
"format": _format,
|
||||
|
||||
"content": content,
|
||||
"sound_link": sound_link,
|
||||
"sound_title": sound_title,
|
||||
"word_times" : word_times
|
||||
}
|
||||
|
||||
bulk_data.append(
|
||||
{"_id": eid, "_source": data_item}
|
||||
)
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print(
|
||||
"=" * 10, "to_elastic , total=" + str(total_count)
|
||||
)
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
except Exception as e:
|
||||
print("error in file " + file + str(e))
|
||||
|
||||
|
||||
|
||||
if len(bulk_data) >= 0:
|
||||
total_count += len(bulk_data)
|
||||
print(
|
||||
"=" * 10, "to_elastic , total=" + str(total_count)
|
||||
)
|
||||
elastic.importBulkList(bulk_data, index_name_o)
|
||||
bulk_data = []
|
||||
|
||||
|
||||
|
||||
+4
@@ -459,5 +459,9 @@ def main_proccess():
|
||||
|
||||
|
||||
|
||||
### --------------------------------------
|
||||
### استخراج فایلهای مرتبط با هر قانون در اکسل خروجی
|
||||
### qavanin_output4.xlsx
|
||||
### --------------------------------------
|
||||
if __name__ == "__main__":
|
||||
main_proccess()
|
||||
+3
-3
@@ -45,7 +45,7 @@ def validate_id(value) :
|
||||
value = value.split('?')[0]
|
||||
return value
|
||||
|
||||
|
||||
#### ارسال اطلاعات از اکسل قبل انقلاب به ایندکس الاستیک mj_qa_qanon
|
||||
def import_excel_before_to_elastic(elastic, path_file, index_name_o, duplicate_list):
|
||||
bulk_data_import=[]
|
||||
bulk_data_update=[]
|
||||
@@ -315,7 +315,7 @@ def import_excel_before_to_elastic(elastic, path_file, index_name_o, duplicate_l
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
|
||||
#### ارسال اطلاعات از اکسل بعد انقلاب به ایندکس الاستیک mj_qa_qanon
|
||||
def import_excel_after_to_elastic(elastic, path_file, index_name_o, duplicate_list):
|
||||
bulk_data_import=[]
|
||||
bulk_data_update=[]
|
||||
@@ -551,7 +551,7 @@ def import_excel_after_to_elastic(elastic, path_file, index_name_o, duplicate_li
|
||||
traceback.print_exc()
|
||||
|
||||
|
||||
|
||||
#### ارسال تصمیمات قانونی از اکسل قبل انقلاب به ایندکس الاستیک mj_qa_qanon
|
||||
def import_excel_tasmimat_to_elastic(elastic, path_file, index_name_o, duplicate_list ):
|
||||
error_list = []
|
||||
bulk_data_import=[]
|
||||
@@ -1,23 +0,0 @@
|
||||
from app.common.config_base import *
|
||||
from app.common.general_functions import *
|
||||
import requests
|
||||
|
||||
|
||||
|
||||
url = " https://tavasi.ir/api/nlp/keywords?content="
|
||||
|
||||
headers = HEADERS
|
||||
text = '''
|
||||
|
||||
دیپلماسی اقتصادی: مجموعه اقدامات و فعالیت های اقتصادی خارجی (توسط دولت یا بخش خصوصی با هماهنگی وزارت امورخارجه) که با هدف توسعه روابط اقتصادی و تجاری با کشورهای خارجی، در جهت دستیابی به اهداف نظیر افزایش دسترسی به بازارهای بین المللی کالاها و خدمات، سرمایه گذاری خارجی، تبادل فناوری و برقراری روابط پایدار با سایر کشورها انجام می شود.
|
||||
'''
|
||||
url = url + text
|
||||
payload = {}
|
||||
response = requests.request("GET", url, headers=headers, data=payload)
|
||||
entities = ''
|
||||
i = len(response.text.strip())-3
|
||||
keywords = response.text[13:i].split(',')
|
||||
# for entity in keywords:
|
||||
# entities = entities + str(entity).strip('\"') +' ' + '\n'
|
||||
print(keywords)
|
||||
|
||||
Reference in New Issue
Block a user