import os import re import traceback import json from dotenv import load_dotenv from config_base import * from elastic_helper import ElasticHelper import pandas as pd from qanon_functions import * def parseBeforeInfos(elastic, file_excel, file_log, result_path = ""): df = pd.read_excel(file_excel, sheet_name=0, header=None) count = 0 rows_list = df.to_dict(orient='records') total = len(df[0]) print('total : ', total) column_names = df.columns.tolist() print(column_names) file = open(file_log, 'w+', encoding='utf8') dict_qanon_id = get_dict_qanon_title("qanon_title_ids.txt") # Print the list of rows dic_error_qanon_title={} dic_error_section_title={} rows_list_new = [] bulk_data = [] total_count=0 try: for row in rows_list: row_id = row[column_names[0]] qanon_title = row[column_names[1]] ts_date = row[column_names[3]] qanon_id = 0 count = count + 1 if (count % 10) == 0 : print("%s, %.2f " % ( '================== ', (count / total) * 100 if total > 0 else 0)) qanon_title = text_normalizer.normalize_search_qanon(qanon_title) # جداسازی اعداد چسبیده به کلمات قبل یا بعد مثل # قانون بودجه سال 1369کل کشور qanon_title = re.sub(r"([^\/])(\d+)([\u0600-\u06FF\u0750-\u077F]+?)", r"\1\2 \3", qanon_title) score = 100 qanon_id = 0 # ابتدا از قانونهای خاص که شناسه ذخیره شده دارند جستجو کند if qanon_title in dict_qanon_id : score = 100 qanon_id = dict_qanon_id[qanon_title] state = 'قانون-دستی' # if qanon_id == 0 : # continue # این قانون در بانک ما وجود ندارد # اگر پیدا نشد، از الاستیک جستجو کند else : qanon_id, score, item = searchQanonId(elastic, "mj_qa_qanon", qanon_title, ts_date) # اگر قابل اطمینان نبود، خطا ثبت کند if score < 90 : dic_error_qanon_title[qanon_title]=count print('-'*10 , str(count) , ' qanon error', qanon_title ) file.write('---- qanon error ---' + str(count) + ' ----- ' + qanon_title + '\n') qanon_id = 0 state = 'خطا-قانون' else: state = 'قانون-جستجو' # ذخیره شناسه ها و وضعیت برای اکسل جدید # row[5]=qanon_id # row[6]=section_id # row[7]=state # rows_list_new.append(row) 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/gateway2_main/repo/_other/" elastic = ElasticHelper(host, password, "elastic", path_base_map) parseBeforeInfos(elastic, "./data/جداول بانک قوانین_info-شناسه قانون یار.xlsx" , "پیشاقانون1.txt", "./data/result") #parseBeforeInfos(elastic, "./data/tcodes", "./data/tcodes/result")