diff --git a/20_LawReg_qanon_ToElastic.py b/20_LawReg_qanon_ToElastic.py deleted file mode 100644 index 6110a38..0000000 --- a/20_LawReg_qanon_ToElastic.py +++ /dev/null @@ -1,191 +0,0 @@ -import json -import requests -from 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 -import sys -import traceback -import re - -from config_base import * -from general_functions import * - - -cursor, cnxn = create_cursor() - -#Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/ -class JSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, Decimal): - return float(obj) - return json.JSONEncoder.default(self, obj) - - -query = ''' -SELECT - l1.[ID] as Id - ,l1.[CAPTION] as title - --,[F_LWBASETABLEID_LAWTYPE] - ,l1.[ISLAW] -- قانون - ,l1.[ISREGULATION] -- مقرره - ,isnull(l1.APPROVEDATE,'') as aproveDate -- تاریخ تصویب - ,isnull(l1.EXPIREDATE,'') as expireDate -- تاریخ انقضا - --,[F_LWBASETABLEID_CLASSIFICATION] - ,[RULENO] - ,[LAWNO] - --,[F_CMBASETABLEID_LASTSTATUS] - ,lss.CAPTION as qanon_etebar - ,cbt.CAPTION as lawType - ,( - 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 l1.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 l1.ID = l2.id - ) as regulationType - - 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 ) - ''' - - - -def isNeedHtml(html): - if " 1000: - # break - # print(row.sectionId) - - - title = normalYehKe( row.title ) - - eid='qq'+ str(row.Id) - - main_type = '' - if(row.ISLAW == 1): - main_type = 'قانون' - elif(row.ISREGULATION == 1): - main_type = 'مقرره' - - sub_type = '' - if(row.ISLAW == 1): - sub_type = row.lawType - elif(row.ISREGULATION == 1): - sub_type = row.regulationType - sub_type = normalYehKe(sub_type) - - qanon_number = '' - if(row.ISLAW == 1): - qanon_number = row.LAWNO - elif(row.ISREGULATION == 1): - qanon_number = row.RULENO - - # other_type = 'اصلی' اصلاحی.... - # action_type ... - - - - ts_year = '' - if row.aproveDate : - items = row.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) - except Exception as e: - sort_date_timestamp = -15000000000 # 9/2/1494, 12:45:44 AM # خطا یا خالی - - expire_date = row.expireDate.strip() - - qanon_etebar = '' - if row.qanon_etebar : - qanon_etebar = row.qanon_etebar - - - data={ - 'id':eid, - 'ref_id':row.Id, - 'main_type': main_type, - 'sub_type': sub_type, - 'title': title, - 'expire_date': expire_date, - 'ts_date': row.aproveDate, - 'ts_year': ts_year, - 'ts_ref': ts_ref, - 'qanon_etebar' : qanon_etebar, - 'sort_date_timestamp': sort_date_timestamp, # created from repairQanon.getSortTimestamp - } - - if bulk_count > 100: - print('=' * 10 ) - print(str(i)+ ', id=' + eid) - - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - # print(response) - # print(response.text) - bulk_data = [] - bulk_count = 0 - # print(response.text) - #print(row.txt) - - bulk_data.append(data) - bulk_count +=1 - - - -if bulk_count > 0: - print(bulk_count) - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - -cursor.close() -cnxn.close() -print('end success') -t2= datetime.datetime.now() -print(t2-t1) diff --git a/21_Relations_qanon_LWReg.py b/21_Relations_qanon_LWReg.py deleted file mode 100644 index f8dbdc2..0000000 --- a/21_Relations_qanon_LWReg.py +++ /dev/null @@ -1,184 +0,0 @@ -import json -import requests -from config_base import * -import requests -from bs4 import BeautifulSoup -from html import escape -import json -from decimal import Decimal -import datetime - - -from config_base import * -from general_functions import * - -cursor, cnxn = create_cursor() - -# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/ -class JSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, Decimal): - return float(obj) - return json.JSONEncoder.default(self, obj) - -# اجرای کوئری SQL و خواندن داده‌ها به یک DataFrame -query = """ -SELECT - l1.F_LWLAWID_LAW as id - , l1.F_LWSECTIONID as section_id - --, l2.CAPTION as from_title - -- ,(select top(1) tt1.id from lwSection tt1 where tt1.F_LWLAWID=l1.F_LWLAWID_LAW and tt1.FULLPATH = 'عنوان') as section_id2 - , l3.[FULLPATH] as from_section_title - , l1.ISREFERENCE - , l1.F_LWLAWID_REGULATION as to_id - , l4.CAPTION as to_title - , 'مقرره' as to_type - - -FROM [Qavanin].[dbo].[lwLawRegulation] l1 -left join lwLaw l2 on l1.F_LWLAWID_LAW=l2.id -left join lwsection l3 on l1.F_LWSECTIONID=l3.id -left join lwLaw l4 on l1.F_LWLAWID_REGULATION=l4.id - -order by l1.F_lwlawid_law, l1.F_LWLAWID_REGULATION , l1.F_LWSECTIONID - -""" - -cursor.execute(query) - -url = BASE_URL + "repo/majles/qaqanon/multi/update" - -headers = HEADERS - - -bulk_count = 1 -bulk_data = [] -previd = '' -ref_state_array = [] - -t1= datetime.datetime.now() -print("start time: " + str(t1)) -i = 0 -all_data = [] -repeat_data = [] - -relations = [] -prev_eid = '' -prev_sectionid = '' -prev_to_id = '' - -while 1: - - i += 1 - row = cursor.fetchone() - if not row: - break - - eid='qq'+ str(row.id) - sectionid = str(row.section_id) - to_id = str(row.to_id) - - - # ارتباط با خودش بی معنی است - # چند مورد در دیتابیس بود - if row.id == row.to_id : - continue - - if eid == prev_eid and to_id == prev_to_id : - if prev_sectionid == sectionid : - continue - - prev_to_id = to_id - prev_sectionid = sectionid - - rel_type = 'عادی' - if int(row.ISREFERENCE) == 1: - rel_type = 'استناد' - - from_type = "کل قانون" - if row.section_id : - from_type = "جزء قانون" - - from_section_title = '' - if row.from_section_title : - from_section_title = row.from_section_title - - to_title = normalYehKe( row.to_title ) - to_type = row.to_type - - - relation = { - "from_type": from_type, - "from_section_id" : sectionid, - "from_section_title" : from_section_title, - "rel_type" : rel_type, - "to_type" : to_type, - "to_id" : to_id , - "to_title" : to_title, - "wait" : 1, - "rel_key" : 'qavanin', - } - - #print('%'*20, 'eid= ', eid, ' , ... prev_eid= ', prev_eid) - #print('--------- relations' , len(relations) ) - #print(relation ) - if (i%100) == 0 : - print('^' * 10, ' id=', eid, ' i=',i) - - if prev_eid == '': - prev_eid = eid - continue - elif prev_eid == eid : - relations.append(relation) - continue - else : - data={ - 'id' : prev_eid, - 'qanon_relations' : relations - } - bulk_data.append(data) - bulk_count +=1 - - prev_eid = eid - relations=[] - relations.append(relation) - - - if bulk_count > 10: - print('=' * 10 ) - print(str(i)+ ', id=' + eid) - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - print(response) - bulk_data = [] - bulk_count = 0 - # print(response.text) - #print(row.txt) - - - -if len(relations) : - data={ - 'id' : prev_eid, - 'qanon_relations' : relations - } - bulk_data.append(data) - bulk_count +=1 - - -# print(bulk_count) -if len(bulk_data) : - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - print(response) - # print(response.text ) - -cursor.close() -cnxn.close() -t2= datetime.datetime.now() -print("update rows count: " + str(len(all_data))) -print("finished time: " + str(t2)) -print("process time: " + str(t2-t1)) -print('*********** end success ***********') - - diff --git a/22_Relations_qanon_opinion.py b/22_Relations_qanon_opinion.py deleted file mode 100644 index c2c6f6e..0000000 --- a/22_Relations_qanon_opinion.py +++ /dev/null @@ -1,189 +0,0 @@ -import json -import requests -from config_base import * -import requests -from bs4 import BeautifulSoup -from html import escape -import json -from decimal import Decimal -import datetime - - -from config_base import * -from general_functions import * - -cursor, cnxn = create_cursor() - -# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/ -class JSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, Decimal): - return float(obj) - return json.JSONEncoder.default(self, obj) - -# اجرای کوئری SQL و خواندن داده‌ها به یک DataFrame -query = """ -SELECT - l1.[F_LWLAWID] as id - ,[F_LWSECTIONID] as sectionid - , ls.[FULLPATH] as from_section_title - ,[ISRELATED] - --,[F_CMBASETABLEID_OPBASEDOCTYPE] - --,l4.CAPTION - ,[F_OPOPINIONID] as to_id - ,og.CAPTION as to_type - ,l3.CAPTION as to_title - - FROM [Qavanin].[dbo].[opOpinionLaw] l1 - left join [opOpinion] l2 on l1.[F_OPOPINIONID] = l2.id - left join opOpiniongiver og on l2.F_OPOPINIONGIVERID = og.id - left join lwLaw l3 on l2.[F_LWLAWID] = l3.id - left join lwsection ls on l1.F_LWSECTIONID=ls.id - - --left join lwLaw l4 on l1.[F_LWLAWID] = l4.id - - order by l1.[F_LWLAWID], [F_OPOPINIONID], [F_LWSECTIONID] - -""" - -cursor.execute(query) - -url = BASE_URL + "repo/majles/qaqanon/multi/update" - -headers = HEADERS - - -bulk_count = 1 -bulk_data = [] -previd = '' -ref_state_array = [] - -t1= datetime.datetime.now() -print("start time: " + str(t1)) -i = 0 -all_data = [] -repeat_data = [] - -relations = [] -prev_eid = '' -prev_sectionid = '' -prev_to_id = '' - -while 1: - - i += 1 - row = cursor.fetchone() - if not row: - break - - eid='qq'+ str(row.id) - sectionid = str(row.sectionid) - to_id = str(row.to_id) - - - if eid == prev_eid and to_id == prev_to_id : - if prev_sectionid == sectionid : - continue - - prev_to_id = to_id - prev_sectionid = sectionid - - rel_type = 'عادی' - if int(row.ISRELATED) == 1: - rel_type = 'استناد' - - from_type = "کل قانون" - if sectionid : - from_type = "جزء قانون" - - from_section_title = '' - if row.from_section_title : - from_section_title = row.from_section_title - - to_title = normalYehKe( row.to_title ) - - to_type = row.to_type.strip() - - if to_type == 'راي هيات عمومي ديوان عدالت اداري' : - to_type = 'رای دیوان عدالت اداری' - if to_type == 'راي وحدت رويه ديوان عالي كشور' : - to_type = 'رای وحدت رویه' - if to_type == 'اداره کل حقوقی قوه قضائیه' : - to_type = 'نشست قضایی' - if to_type == 'نظر رياست مجلس - اصول 85 و 138' : - to_type = 'نظر ریاست مجلس' - - relation = { - "from_type": from_type, - "from_section_id" : sectionid, - "from_section_title" : from_section_title, - "rel_type" : rel_type, - "to_type" : to_type, - "to_id" : to_id , - "to_title" : to_title, - "wait" : 1, - "rel_key" : 'qavanin', - } - - #print('%'*20, 'eid= ', eid, ' , ... prev_eid= ', prev_eid) - #print('--------- relations' , len(relations) ) - #print(relation ) - if (i%100) == 0 : - print('^' * 10, ' id=', eid, ' i=',i) - - if prev_eid == '': - prev_eid = eid - continue - elif prev_eid == eid : - relations.append(relation) - continue - else : - data={ - 'id' : prev_eid, - 'opinion_relations' : relations - } - bulk_data.append(data) - bulk_count +=1 - - prev_eid = eid - relations=[] - relations.append(relation) - - - if bulk_count > 10: - print('=' * 10 ) - print(str(i)+ ', id=' + eid) - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - print(response) - bulk_data = [] - bulk_count = 0 - # print(response.text) - #print(row.txt) - - - -if len(relations) : - data={ - 'id' : prev_eid, - 'opinion_relations' : relations - } - bulk_data.append(data) - bulk_count +=1 - - -# print(bulk_count) -if len(bulk_data) : - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - print(response) - # print(response.text ) - -cursor.close() -cnxn.close() -t2= datetime.datetime.now() -print("update rows count: " + str(len(all_data))) -print("finished time: " + str(t2)) -print("process time: " + str(t2-t1)) -print('*********** end success ***********') - diff --git a/23_LawReg_lwphase_Info.py b/23_LawReg_lwphase_Info.py deleted file mode 100644 index 077369d..0000000 --- a/23_LawReg_lwphase_Info.py +++ /dev/null @@ -1,213 +0,0 @@ -import json -import requests -from config_base import * -import requests -from bs4 import BeautifulSoup -from html import escape -import json -from decimal import Decimal -import datetime - - -from config_base import * -from general_functions import * - -# موقت -# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد - -cursor, cnxn = create_cursor() - -# Does quasi the same things as json.loads from here: https://pypi.org/project/dynamodb-json/ -class JSONEncoder(json.JSONEncoder): - def default(self, obj): - if isinstance(obj, Decimal): - return float(obj) - return json.JSONEncoder.default(self, obj) - -query='SELECT ID,CAPTION FROM [Qavanin].[dbo].[cmOrganization]' -cursor.execute(query) - -ORG_DICT = {} - -while True: - row = cursor.fetchone() - if not row: - break - - - rr = {"id" : int(row.ID), 'title': row.CAPTION} - ORG_DICT[str(int(row.ID))] = {"id" : row.ID, 'title': row.CAPTION} - -#نکته : برای مقررات هیچ موردی نبود که جدولی باشد -query = ''' - - SELECT - F_LWLAWID as F_LWLAWID, - p.ID as Phase_ID, - isnull(COMMANDDATE,'') as COMMANDDATE , - isnull(COMMANDNO,'') as COMMANDNO, - isnull(NEWSPAPERDATE,'') as NEWSPAPERDATE, - isnull(NEWSPAPERNO,'') as NEWSPAPERNO, - isnull(o.CAPTION,'') as organization_title - ,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_CMORGANIZATIONID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM [lwReceiver] where F_LWLAWID=p.[F_LWLAWID]) as receiver - ,(SELECT STRING_AGG(CONVERT(NVARCHAR(max),F_CMORGANIZATIONID), ',') WITHIN GROUP (ORDER BY ID) AS AggregatedResult FROM [lwExecutor] where F_LWLAWID=p.[F_LWLAWID]) as exceuter - ,(SELECT top (1) [EXECUTIONDATE] FROM [lwExecuteCondition] where [F_PHASEID]=p.id) as EXECUTIONDATE - FROM [Qavanin].[dbo].[lwPhase] p - left join cmOrganization o on p.F_CMORGANIZATIONID = o.ID - left join lwLaw l1 on p.F_LWLAWID= l1.ID - - -- order by F_LWLAWID --بعضی موارد تکرار شده اند - ''' - -cursor.execute(query) - - -url = BASE_URL + "repo/majles/qaqanon/multi/update" - -headers = HEADERS - -bulk_count = 1 -bulk_data = [] -previd = '' -ref_state_array = [] - -t1= datetime.datetime.now() -print("start time: " + str(t1)) -i = 0 -all_data = [] -repeat_data = [] -while 1: - - i += 1 - row = cursor.fetchone() - if not row: - break - phase_id = str(int(row.Phase_ID.real)) - law_id = str(int(row.F_LWLAWID.real)) - eb_number = row.COMMANDNO.strip() if row.COMMANDNO else '' - eb_date = row.COMMANDDATE.strip() if row.COMMANDDATE else '' - eb_ref = row.organization_title.strip() if row.organization_title else '' # نرمالایز میخواد؟ - rrk_number = row.NEWSPAPERNO.strip() if row.NEWSPAPERNO else '' - rrk_date = row.NEWSPAPERDATE.strip() if row.NEWSPAPERDATE else '' - exec_date = row.EXECUTIONDATE.strip() if row.EXECUTIONDATE else '' - receiver_ids = row.receiver - exceuter_ids = row.exceuter - - if eb_date == '0000/00/00' : - eb_date = '' - if rrk_date == '0000/00/00' : - rrk_date = '' - if exec_date == '0000/00/00' : - exec_date = '' - - if eb_number == 'نامعلوم' or eb_number == 'ندارد': - eb_number = '' - if rrk_number == 'نامعلوم' or rrk_number == 'ندارد': - rrk_number = '' - - # # جایگذاری مقدار خالی به جای نامعلوم - # if eb_number.__contains__("معلوم"): - # eb_number = "" - # if eb_date.__contains__("معلوم"): - # eb_date = "" - # if eb_ref.__contains__("معلوم"): - # eb_ref = "" - # if rrk_number.__contains__("معلوم"): - # rrk_number = "" - # if rrk_date.__contains__("معلوم"): - # rrk_date = "" - - # کمتر از 10 مورد تکرار داشتند، ظاهرا چند بار در روزنامه رسمی منتشر شده و هر بار بخشی از آن ، لذا اولین اطلاعات پر آن برداشته شد - if law_id == '178971': - eb_number = "7644 ج" - if law_id == '244878': - eb_number = "" - if law_id == '83695': - eb_number = "3923" - if law_id == '115887': - eb_number = "" - if law_id == '113211': - eb_number = "" - if law_id == '83452': - eb_number = "70445" - if law_id == '111876': - eb_number = "7848" - if law_id == '198907': - eb_number = "36094" - if law_id == '87694': - eb_number = "36341/ 1" - - if law_id in all_data: - repeat_data.append(law_id) - continue - - all_data.append(law_id) - # print("row: %s" % str(i)) - - receiver_organs = [] - if receiver_ids : - for id in receiver_ids.split(',') : - if id in ORG_DICT : - receiver_organs.append({ "id": id, "title":ORG_DICT[id]["title"]}) - - exceuter_organs = [] - if exceuter_ids : - for id in exceuter_ids.split(',') : - if id in ORG_DICT : - exceuter_organs.append({ "id": id, "title":ORG_DICT[id]["title"]}) - - - - eid= 'qq' + law_id - - eblagh = { - 'number' : eb_number, - 'date' : eb_date, - 'from' : eb_ref, - } - - rrk = { - 'number' : rrk_number, - 'date' : rrk_date, - } - - data={ - 'id' : eid, - 'eblagh' : eblagh, - 'rrk': rrk, - 'exec_date' : exec_date, - 'receiver_organs' : receiver_organs, - 'exceuter_organs' : exceuter_organs, - } - - - if bulk_count > 100: - print('=' * 10 ) - print(str(i)+ ', id=' + eid) - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - print(response) - bulk_data = [] - bulk_count = 0 - # print(response.text) - #print(row.txt) - - bulk_data.append(data) - bulk_count +=1 - - -# print(bulk_count) -if len(bulk_data) : - payload = json.dumps(bulk_data, cls=JSONEncoder) #Works! - response = requests.request("POST", url, headers=headers, data=payload) - print(response) - # print(response.text ) - -cursor.close() -cnxn.close() -t2= datetime.datetime.now() -print("update rows count: " + str(len(all_data))) -print("finished time: " + str(t2)) -print("process time: " + str(t2-t1)) -print('*********** end success ***********') -