refactor folders 4
This commit is contained in:
@@ -9,12 +9,6 @@ from common.elastic_helper import ElasticHelper
|
|||||||
from create_relation_tags import *
|
from create_relation_tags import *
|
||||||
from temp_refactor_gn_dataset import *
|
from temp_refactor_gn_dataset import *
|
||||||
|
|
||||||
from temp_LawSection_content import *
|
|
||||||
|
|
||||||
# cursor, cnxn = create_cursor()
|
|
||||||
# import_law_section_to_elastic(cursor)
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv(dotenv_path='config.env')
|
load_dotenv(dotenv_path='config.env')
|
||||||
|
|
||||||
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
import json
|
|
||||||
import requests
|
|
||||||
from common.config_base import *
|
|
||||||
import pyodbc
|
|
||||||
import requests
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from html import escape
|
|
||||||
import json
|
|
||||||
from decimal import Decimal
|
|
||||||
import datetime
|
|
||||||
import time
|
|
||||||
from common.config_base import *
|
|
||||||
from common.general_functions import *
|
|
||||||
from common.text_normalizer import TextNormalizer
|
|
||||||
|
|
||||||
|
|
||||||
# cursor, cnxn = create_cursor()
|
|
||||||
|
|
||||||
def import_law_section_to_elastic(cursor) :
|
|
||||||
|
|
||||||
query = '''
|
|
||||||
select
|
|
||||||
s.ID as sectionId
|
|
||||||
,isnull(s.CAPTION,'') as title -- عنوان بخش: مثلا ماده 5
|
|
||||||
,isnull(s.F_PARENTID,0) as parentId
|
|
||||||
,isnull(lss.CAPTION,'') as sectionStatus -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
|
||||||
,isnull(lss2.CAPTION,'') as qanon_etebar -- برای کل قانون نه جزء یا ماده خاص : ... منسوخه، معتبر، اصلاحی، موقت و
|
|
||||||
,isnull(s.SECTIONTEXT,'') as sectionText -- متن ماده یا تبصره
|
|
||||||
,isnull(s.SECTIONLEVEL,0) as sectionLevel -- نسبت به عنوان قانون نامرتب و دارای مقدار تکراری هم هست ؟؟؟
|
|
||||||
,isnull(nestedLawType.CAPTION,'') as lawType
|
|
||||||
--,isnull(nestedLawStatus.CAPTION,'') as lawStatus
|
|
||||||
,isnull(s.TEXTORDER,0) as textOrder -- ترتیب نمایش مواد و تبصره ها
|
|
||||||
,s.STATENO as stateNo -- ???
|
|
||||||
,isnull(s.SECTIONTYPENO,0) as sectionTypeNumber -- دوهزار رکورد با مقدار صفر دارد اما مقادیر دیگری نیز پذیرفته است ؟؟؟
|
|
||||||
-- بیش از پنج هزار رکورد با مقدار بالاتر از 1500 دارد که چنین مقادیری در جدول سکشن_تایپ وجود ندارد پس با این جدول رابطه ندارد
|
|
||||||
,isnull(l.CAPTION,'') as lawTitle -- عنوان قانون
|
|
||||||
,isnull(l.ID,0) as lawId -- شناسه قانون
|
|
||||||
,isnull(l.APPROVEDATE,'') as aproveDate -- تاریخ تصویب
|
|
||||||
,isnull(l.EXPIREDATE,'') as expireDate -- تاریخ انقضا
|
|
||||||
--,isnull(s.F_LWPHASEID,0) as phaseId -- شناسه فاز
|
|
||||||
,s.FULLPATH as sectionFullPath -- عنوان ماده یا تبصره
|
|
||||||
,isnull(s.SECTIONTYPENOTEXT,'') as sectionType -- ??? استفساریه، کنوانسیون، موافقت نامه، اساسنامه، تفسیر، دوم ، سوم ، چهارم، دوازدهم، خالی، 1، 2، 3، 4
|
|
||||||
,isnull(s.FIRSTSATENO,0) as firstStateNo -- ??? بازه 0 تا 169
|
|
||||||
,isnull(s.LASTSTATENO,0) as lastStateNo -- ??? بازه 0 تا 112
|
|
||||||
,isnull(s.HIERARCHY,'') as hierarchy
|
|
||||||
,isnull(s.DISPLAYINCONTENTS,0) as displayInContents -- ??? صد و پنجاه و سه رکورد دارای مقدار یک و بقیه یک میلیون رکورد مقدار 0 دارد
|
|
||||||
,isnull(s.ISINTERPRETATION,0) as isInterpretation -- ??? چهارصد و پنجاه و سه رکورد با مقدار یک دارد و بقیه مقادیر نال است
|
|
||||||
,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_TOPICID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM lwsectiontopic where [F_SECTIONID]=s.id) as topics
|
|
||||||
,l.[ISLAW] -- قانون
|
|
||||||
,l.[ISREGULATION] -- مقرره
|
|
||||||
,l.[ISCORRECTIONLETTER] -- اصلاحیه
|
|
||||||
,(
|
|
||||||
SELECT top (1) p3.CAPTION
|
|
||||||
FROM [lwPhase] p1
|
|
||||||
left join [lwApprover] p2 on p1.ID=p2.F_LWPHASEID
|
|
||||||
left join cmOrganization p3 on p2.F_CMORGANIZATIONID = p3.id
|
|
||||||
where l.ID = p1.F_LWLAWID
|
|
||||||
order by p2.APPROVEDATE asc
|
|
||||||
) as ts_ref -- مرجع تصویب
|
|
||||||
,(
|
|
||||||
SELECT cbt.CAPTION
|
|
||||||
FROM lwLaw l2
|
|
||||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
|
||||||
where l.ID = l2.id
|
|
||||||
) as regulationType
|
|
||||||
|
|
||||||
|
|
||||||
from lwSection s
|
|
||||||
left join lwLawSectionStatus lss on s.F_CMBASETABLEID_SECTIONSTATUS = lss.ID
|
|
||||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
|
||||||
left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS]
|
|
||||||
left JOIN (
|
|
||||||
SELECT l2.F_LWBASETABLEID_LAWTYPE,l2.ID,cbt.CAPTION
|
|
||||||
FROM lwLaw l2
|
|
||||||
left JOIN cmBasetable cbt ON l2.F_LWBASETABLEID_LAWTYPE = cbt.ID
|
|
||||||
) AS nestedLawType ON s.F_LWLAWID = nestedLawType.ID
|
|
||||||
left JOIN (
|
|
||||||
SELECT l2.[F_LWBASETABLEID_REGULATIONTYPE],l2.ID,cbt.CAPTION
|
|
||||||
FROM lwLaw l2
|
|
||||||
left JOIN cmBasetable cbt ON l2.[F_LWBASETABLEID_REGULATIONTYPE] = cbt.ID
|
|
||||||
) AS nestedRegulationType ON s.F_LWLAWID = nestedRegulationType.ID
|
|
||||||
|
|
||||||
where l.ISLAW = 1
|
|
||||||
order by s.F_LWLAWID,textOrder
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
cursor.execute(query)
|
|
||||||
text_normal = TextNormalizer()
|
|
||||||
|
|
||||||
# url = BASE_URL + "repo/majles/section/multi/add"
|
|
||||||
url = BASE_URL + "repo/majles/section/multi/update"
|
|
||||||
# dict_topic = json.loads(open("list_LWTopic.json").read())
|
|
||||||
|
|
||||||
headers = HEADERS
|
|
||||||
|
|
||||||
total_count = 0
|
|
||||||
bulk_data = []
|
|
||||||
|
|
||||||
t1= datetime.datetime.now()
|
|
||||||
print(t1)
|
|
||||||
i = 0
|
|
||||||
while 1:
|
|
||||||
# print(i)
|
|
||||||
i=i+1
|
|
||||||
row = cursor.fetchone()
|
|
||||||
if not row:
|
|
||||||
break
|
|
||||||
|
|
||||||
# if i > 1000:
|
|
||||||
# break
|
|
||||||
# print(row.sectionId)
|
|
||||||
|
|
||||||
html = ''
|
|
||||||
if isNeedHtml(row.sectionText) :
|
|
||||||
html = row.sectionText
|
|
||||||
|
|
||||||
try:
|
|
||||||
soup = BeautifulSoup(row.sectionText, "html.parser")
|
|
||||||
text = soup.get_text("\n", strip=True)
|
|
||||||
# text = removeHtmlNoTableTag(row.sectionText) # خطا داره
|
|
||||||
except Exception as e:
|
|
||||||
text = row.sectionText
|
|
||||||
|
|
||||||
|
|
||||||
text = text_normal.normalize_qanon(text)
|
|
||||||
content_len = text.__len__()
|
|
||||||
word_len = len(text_normal.split_words(text))
|
|
||||||
|
|
||||||
eid='qs'+ str(row.sectionId)
|
|
||||||
|
|
||||||
|
|
||||||
data={
|
|
||||||
'id':eid,
|
|
||||||
'content': text,
|
|
||||||
'content_len': content_len,
|
|
||||||
'word_len': word_len
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(bulk_data) >= 200:
|
|
||||||
total_count += len(bulk_data)
|
|
||||||
print('=' * 5, 'law_section ===', ', 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)
|
|
||||||
print(' ' * 10, 'len(payload) ===', str(len(payload)), ' > 8388608 , len(pops_data)='+str(len(pops_data)) )
|
|
||||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
|
||||||
|
|
||||||
|
|
||||||
response = requests.request("POST", url, headers=headers, data=payload)
|
|
||||||
if response.status_code != 200 :
|
|
||||||
print('*' * 10, ' error : len(bulk_data)=', str(len(bulk_data)), ' bulk_data[0]='+ str(bulk_data[0]['id']) , ' bulk_data[-1]='+ str(bulk_data[-1]['id']))
|
|
||||||
print(response.text)
|
|
||||||
bulk_data = pops_data
|
|
||||||
continue
|
|
||||||
|
|
||||||
bulk_data = pops_data
|
|
||||||
# print(response)
|
|
||||||
# print(response.text)
|
|
||||||
# print(row.txt)
|
|
||||||
|
|
||||||
bulk_data.append(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('end success import_law_section_to_elastic')
|
|
||||||
t2= datetime.datetime.now()
|
|
||||||
print(t2-t1)
|
|
||||||
@@ -7,12 +7,6 @@ from common.elastic_helper import ElasticHelper
|
|||||||
from create_relation_tags import *
|
from create_relation_tags import *
|
||||||
from temp_refactor_gn_dataset import *
|
from temp_refactor_gn_dataset import *
|
||||||
|
|
||||||
from temp_LawSection_content import *
|
|
||||||
|
|
||||||
# cursor, cnxn = create_cursor()
|
|
||||||
# import_law_section_to_elastic(cursor)
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv(dotenv_path='config.env')
|
load_dotenv(dotenv_path='config.env')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ from common.elastic_helper import ElasticHelper
|
|||||||
from create_relation_tags import *
|
from create_relation_tags import *
|
||||||
from temp_refactor_gn_dataset import *
|
from temp_refactor_gn_dataset import *
|
||||||
|
|
||||||
from temp_LawSection_content import *
|
|
||||||
|
|
||||||
# cursor, cnxn = create_cursor()
|
|
||||||
# import_law_section_to_elastic(cursor)
|
|
||||||
|
|
||||||
|
|
||||||
load_dotenv(dotenv_path='config.env')
|
load_dotenv(dotenv_path='config.env')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user