refactor to auto import
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
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 s.ID as sectionId
|
||||
,isnull(lss2.CAPTION,'') as qanon_etebar -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
FROM [Qavanin].[dbo].[lwSection] s
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS]
|
||||
where l.ISLAW = 1
|
||||
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 0
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
# 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 = normalYehKe(text)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
qanon_etebar = ''
|
||||
if row.qanon_etebar :
|
||||
qanon_etebar = row.qanon_etebar
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
'qanon_etebar' : qanon_etebar
|
||||
}
|
||||
|
||||
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)
|
||||
bulk_data = []
|
||||
bulk_count =0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
print(bulk_count)
|
||||
if bulk_count >= 1:
|
||||
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()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
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 s.ID as sectionId
|
||||
,isnull(lss2.CAPTION,'') as qanon_etebar -- lwLawSectionStatus_table: ... منسوخه، معتبر، اصلاحی، موقت و
|
||||
FROM [Qavanin].[dbo].[lwSection] s
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
left join lwLawSectionStatus lss2 on lss2.id= l.[F_CMBASETABLEID_LASTSTATUS]
|
||||
where l.[ISREGULATION] = 1
|
||||
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/rgsection/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 0
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
# 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 = normalYehKe(text)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
|
||||
qanon_etebar = ''
|
||||
if row.qanon_etebar :
|
||||
qanon_etebar = row.qanon_etebar
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
'qanon_etebar' : qanon_etebar
|
||||
}
|
||||
|
||||
if bulk_count > 500:
|
||||
print('=' * 10 )
|
||||
print(str(i)+ ', id=' + eid)
|
||||
payload = json.dumps(bulk_data, cls=JSONEncoder) #Works!
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
bulk_data = []
|
||||
bulk_count =0
|
||||
# print(response.text)
|
||||
#print(row.txt)
|
||||
|
||||
bulk_data.append(data)
|
||||
bulk_count +=1
|
||||
|
||||
|
||||
print(bulk_count)
|
||||
if bulk_count >= 1:
|
||||
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()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import requests
|
||||
import json
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
|
||||
# موقت
|
||||
# این برنامه موقتا بخاطر اصلاح داده اجرا شد، اگر از ابتدا انتقال داده انجام شود این بخش خودکار انجام خواهد شد
|
||||
|
||||
|
||||
cursor, cnxn = create_cursor()
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
ADD_ITEM_ROUTE = "subject/edit"
|
||||
TYPE = 3
|
||||
GET_H = lambda x: x["HIERARCHY"]
|
||||
GET_F = lambda x: x["F_PARENTID"]
|
||||
|
||||
|
||||
projectid = 3
|
||||
|
||||
EXAMPLE_ADD_ITEM_QUERY = {
|
||||
"title": "",
|
||||
"projectid": projectid,
|
||||
"listtype": 0,
|
||||
"parent": 0,
|
||||
}
|
||||
|
||||
|
||||
|
||||
query = """select * from dbo.lwtopic"""
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
result = []
|
||||
|
||||
while True:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
ADD_ITEM_QUERY = {
|
||||
"projectid": projectid,
|
||||
"otherid": row.ID,
|
||||
"meta": row.CODE,
|
||||
}
|
||||
result = requests.post(BASE_URL + 'list/' + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||
print(str(row.ID))
|
||||
# result = sorted(result, key=GET_F)
|
||||
result = sorted(result, key=GET_H)
|
||||
|
||||
|
||||
print('finish')
|
||||
@@ -0,0 +1,97 @@
|
||||
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 * FROM [Qavanin].[dbo].[lwLaw]
|
||||
where ISLAW=1
|
||||
'''
|
||||
|
||||
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
|
||||
law_id = row.ID
|
||||
caption = str(row.CAPTION)
|
||||
|
||||
eid= 'qq' + str(law_id)
|
||||
|
||||
title_type = getTitleType(caption)
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
'title_type': title_type
|
||||
}
|
||||
|
||||
|
||||
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 ***********')
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
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 s.ID as sectionId
|
||||
,[SECTIONTEXT] as sectionText
|
||||
FROM [Qavanin].[dbo].[lwSection] s
|
||||
left join lwLaw l on s.F_LWLAWID = l.ID
|
||||
where l.ISLAW = 1 and SECTIONTEXT like '%<TABLE%' or SECTIONTEXT like '%<table%'
|
||||
order by F_LWLAWID, TEXTORDER
|
||||
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
bulk_count = 1
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
ref_state_array = []
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
print(row.sectionId)
|
||||
|
||||
# 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 = normalYehKe(text)
|
||||
|
||||
eid='qs'+ str(row.sectionId)
|
||||
html = row.sectionText
|
||||
|
||||
data={
|
||||
'id' : eid,
|
||||
# 'content': text,
|
||||
'html' : escape(html)
|
||||
}
|
||||
|
||||
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 bulk_count >= 1:
|
||||
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()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
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 sys
|
||||
import traceback
|
||||
import re
|
||||
|
||||
from config_base import *
|
||||
from general_functions import *
|
||||
|
||||
# این برنامه یک بار فقط جهت انتقال کدهای دیتابیس آقای شاهنوش به دیتابیس نهایی قوانین انجام شد
|
||||
# تکرار لازم نیست
|
||||
# در بقیه حالات اگر کدها تغییر نکرده باشد در خود الاستیک بروز رسانی می شود
|
||||
|
||||
|
||||
cursor, cnxn = create_cursor('db4minaei')
|
||||
|
||||
#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)
|
||||
|
||||
|
||||
plan1 = {}
|
||||
query = """select * from dbo.[lwplan] where [f_parentid]=766 order by [ordno] """
|
||||
cursor.execute(query)
|
||||
i = 0
|
||||
while 1:
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
plan1[row.ID] = normalYehKe(row.caption)
|
||||
|
||||
# print(plan1)
|
||||
|
||||
plan2 = {}
|
||||
query = """select * from dbo.[lwplan] where [f_parentid]=21185 order by [ordno] """
|
||||
cursor.execute(query)
|
||||
i = 0
|
||||
while 1:
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
plan2[row.ID] = normalYehKe(row.caption)
|
||||
|
||||
# print(plan2)
|
||||
|
||||
# #########################################################
|
||||
|
||||
query = '''
|
||||
SELECT [f_lwplanid]
|
||||
,[f_lwlawsecid]
|
||||
,[planstate]
|
||||
,[ID]
|
||||
FROM [db4minaei].[dbo].[lwlawplan]
|
||||
where f_lwlawsecid is not null and f_lwlawsecid > 0
|
||||
order by f_lwlawsecid, planstate, f_lwplanid
|
||||
|
||||
'''
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = BASE_URL + "repo/majles/section/multi/update"
|
||||
dict_topic = json.loads(open("list_LWTopic.json").read())
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
total_count = 0
|
||||
bulk_data = []
|
||||
previd = ''
|
||||
|
||||
tcode_main_old = []
|
||||
tcode_sub_old = []
|
||||
tcode_main = []
|
||||
tcode_sub = []
|
||||
prev_sectionid = 0
|
||||
prev_planid = 0
|
||||
prev_planstate = 0
|
||||
|
||||
prev2_sectionid = 0
|
||||
prev2_planid = 0
|
||||
prev2_planstate = 0
|
||||
|
||||
t1= datetime.datetime.now()
|
||||
print(t1)
|
||||
i = 0
|
||||
while 1:
|
||||
# print(i)
|
||||
i=i+1
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
# if i > 3:
|
||||
# break
|
||||
# print(row.sectionId)
|
||||
|
||||
sectionid = row.f_lwlawsecid
|
||||
planid = row.f_lwplanid
|
||||
planstate = row.planstate
|
||||
|
||||
if prev_sectionid == 0 :
|
||||
prev_sectionid = sectionid
|
||||
prev_planid = planid
|
||||
prev_planstate = planstate
|
||||
continue
|
||||
|
||||
|
||||
if sectionid == prev_sectionid and planid == prev_planid and planstate == prev_planstate :
|
||||
continue
|
||||
|
||||
|
||||
if sectionid == prev_sectionid :
|
||||
if prev_planid in plan1 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main_old.append(plan1[prev_planid])
|
||||
else :
|
||||
tcode_sub_old.append(plan1[prev_planid])
|
||||
|
||||
|
||||
elif prev_planid in plan2 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main.append(plan2[prev_planid])
|
||||
else :
|
||||
tcode_sub.append(plan2[prev_planid])
|
||||
prev_planid = planid
|
||||
prev_planstate = planstate
|
||||
continue
|
||||
|
||||
|
||||
eid='qs'+ str(prev_sectionid)
|
||||
data={
|
||||
'id' : eid,
|
||||
'tcode_main' : tcode_main,
|
||||
'tcode_sub' : tcode_sub,
|
||||
'tcode_main_old' : tcode_main_old,
|
||||
'tcode_sub_old' : tcode_sub_old,
|
||||
}
|
||||
|
||||
# print(eid)
|
||||
|
||||
bulk_data.append(data)
|
||||
prev_sectionid = sectionid
|
||||
tcode_main_old = []
|
||||
tcode_sub_old = []
|
||||
tcode_main = []
|
||||
tcode_sub = []
|
||||
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ', 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 == 500 :
|
||||
print(response.text)
|
||||
bulk_data = []
|
||||
break
|
||||
|
||||
bulk_data = pops_data
|
||||
# print(response)
|
||||
# print(response.text)
|
||||
# print(row.txt)
|
||||
|
||||
# /////////////////
|
||||
prev2_sectionid = prev_sectionid
|
||||
prev2_planid = prev_planid
|
||||
prev2_planstate = prev_planstate
|
||||
|
||||
prev_sectionid = sectionid
|
||||
prev_planid = planid
|
||||
prev_planstate = planstate
|
||||
|
||||
|
||||
|
||||
|
||||
# if prev2_sectionid == prev_sectionid :
|
||||
if prev_planid in plan1 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main_old.append(plan1[prev_planid])
|
||||
else :
|
||||
tcode_sub_old.append(plan1[prev_planid])
|
||||
|
||||
|
||||
elif prev_planid in plan2 :
|
||||
if prev_planstate == 1 :
|
||||
tcode_main.append(plan2[prev_planid])
|
||||
else :
|
||||
tcode_sub.append(plan2[prev_planid])
|
||||
# else :
|
||||
|
||||
|
||||
eid='qs'+ str(prev_sectionid)
|
||||
data={
|
||||
'id' : eid,
|
||||
'tcode_main' : tcode_main,
|
||||
'tcode_sub' : tcode_sub,
|
||||
'tcode_main_old' : tcode_main_old,
|
||||
'tcode_sub_old' : tcode_sub_old,
|
||||
}
|
||||
|
||||
bulk_data.append(data)
|
||||
|
||||
if len(bulk_data) > 0:
|
||||
total_count += len(bulk_data)
|
||||
print('=' * 10, ', 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)
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
t2= datetime.datetime.now()
|
||||
print(t2-t1)
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
import pyodbc
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from html import escape
|
||||
import sys
|
||||
import json
|
||||
from decimal import Decimal
|
||||
|
||||
from general_functions import *
|
||||
cursor = 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 F_LWSECTIONID1
|
||||
,l1.[F_LWLAWID] as F_LWLAWID1
|
||||
,l1.F_LWPHASEID as F_LWPHASEID1
|
||||
,l1.[F_LWSECTIONID_REPLACED] as F_LWSECTIONID2
|
||||
,l3.SECTIONTEXT
|
||||
,l4.F_LWLAWID_EFFECTIVE as F_LWLAWID2
|
||||
,l4.F_LWPHASEID_EFFECTIVE as F_LWPHASEID2
|
||||
FROM [AIPLawDCIT].[dbo].[lwsection] l1
|
||||
left join [AIPLawDCIT].[dbo].[lwsection] l2 on l1.F_LWSECTIONID_REPLACED = l2.id
|
||||
left join lwsectionlog l3 on l1.id=l3.F_LWSECTIONID
|
||||
left join lwlawchange l4 on l1.[F_LWLAWCHANGEID]=l4.id
|
||||
left join lwphase l6 on l4.F_LWLAWID_EFFECTIVE = l6.id
|
||||
where l1.[F_LWSECTIONID_REPLACED] is not null
|
||||
order by l1.F_LWLAWID'''
|
||||
|
||||
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
url = "https://api.tavasi.ir/repo/majles/section/add"
|
||||
url_relation = "https://api.tavasi.ir/relation/main/add"
|
||||
|
||||
headers = HEADERS
|
||||
|
||||
headers2 = {
|
||||
"Accept": ACCEPT,
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Authorization": TOKEN,
|
||||
}
|
||||
|
||||
rel_id_replaced = 100
|
||||
rel_id_effective = 102
|
||||
|
||||
|
||||
i = 1
|
||||
while 1:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
print(str(i)+ ', qanonid='+str(row.F_LWLAWID1) + ', id=' + str(row.F_LWSECTIONID1))
|
||||
i=i+1
|
||||
|
||||
if row.F_LWLAWID2 is not None and str(row.F_LWLAWID2) != '' :
|
||||
payload = {
|
||||
"check_exist": 1,
|
||||
"service_id1": 'repo',
|
||||
"entity_type1": 'mqanon',
|
||||
"entity_id1": 'mj_mtaghnin_'+ str(row.F_LWLAWID2),
|
||||
"relation_id": rel_id_effective,
|
||||
"service_id2": 'repo',
|
||||
"entity_type2": 'mqanon',
|
||||
"entity_id2": 'mj_mtaghnin_'+ str(row.F_LWLAWID1),
|
||||
}
|
||||
response = requests.request("POST", url_relation, headers=headers2, data=payload)
|
||||
print(response)
|
||||
|
||||
|
||||
payload = {
|
||||
"check_exist": 0,
|
||||
"service_id1": 'repo',
|
||||
"entity_type1": 'mqsection',
|
||||
"entity_id1": 'mj_mq_section_'+ str(row.F_LWSECTIONID2),
|
||||
"relation_id": rel_id_replaced,
|
||||
"service_id2": 'repo',
|
||||
"entity_type2": 'mqsection',
|
||||
"entity_id2": 'mj_mq_section_'+ str(row.F_LWSECTIONID1),
|
||||
}
|
||||
response = requests.request("POST", url_relation, headers=headers2, data=payload)
|
||||
print(response)
|
||||
|
||||
|
||||
|
||||
# if row.SECTIONTEXT is not None and str(row.SECTIONTEXT) != '' :
|
||||
# eid = 'mj_mq_section_'+ str(row.F_LWSECTIONID2)
|
||||
# new_content = row.SECTIONTEXT
|
||||
# soup = BeautifulSoup(new_content, "html.parser")
|
||||
# text = soup.get_text("\n", strip=True)
|
||||
# content_len = text.__len__()
|
||||
|
||||
# data={
|
||||
# 'id':eid,
|
||||
# 'content': new_content,
|
||||
# 'content_len': content_len,
|
||||
# 'ref_content':escape(new_content)
|
||||
# }
|
||||
|
||||
# payload = json.dumps(data, cls=JSONEncoder) #Works!
|
||||
# response = requests.request("POST", url, headers=headers, data=payload)
|
||||
# result = json.loads( response )
|
||||
# # result["meta"][0]["1"]
|
||||
|
||||
cursor.close()
|
||||
cnxn.close()
|
||||
print('end success')
|
||||
Binary file not shown.
@@ -0,0 +1,26 @@
|
||||
import pyodbc
|
||||
|
||||
TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE2OTM5MDgzMDksImp0aSI6IjZDREM2UjB4ZFh2Y0hMUzBmdTVUQnpjZ1lLZHNMOXdEIiwiaXNzIjoiaHR0cHM6XC9cL2NwLmhhbWZhaG1pLmlyIiwiZXhwIjoxNjk1MjA4MzA4LCJhdWQiOiJodHRwczpcL1wvY3AuaGFtZmFobWkuaXIiLCJkYXRhIjp7ImlkIjoyLCJmaXJzdF9uYW1lIjoiXHUwNjJkXHUwNjQ1XHUwNmNjXHUwNjJmIiwibGFzdF9uYW1lIjoiXHUwNjM1XHUwNjQxXHUwNjI3XHUwNmNjXHUwNmNjIiwiZW1haWwiOiJzYWZhZWkuaGFtaWRAZ21haWwuY29tIiwidXNlcm5hbWUiOiJoc2FmYWVpIiwidXNlcl9sZXZlbCI6Mn19.soDo9t8FtinMamONlivJFGEVRLHOtjBOg5gzt55QVzg"
|
||||
ACCEPT = "application/json"
|
||||
HEADERS = {"Authorization": TOKEN, "Accept": ACCEPT}
|
||||
|
||||
def create_cursor():
|
||||
server = "DESKTOP-ENVCI85"
|
||||
database = "AIPLawDCIT"
|
||||
username = "Mofid3"
|
||||
password = "12345"
|
||||
|
||||
# ENCRYPT defaults to yes starting in ODBC Driver SQL Server. It's good to always specify ENCRYPT=yes on the client side to avoid MITM attacks.
|
||||
cnxn = pyodbc.connect(
|
||||
"DRIVER={SQL Server};SERVER="
|
||||
+ server
|
||||
+ ";DATABASE="
|
||||
+ database
|
||||
+ ";Trusted_Connection=yes;UID="
|
||||
+ username
|
||||
+ ";PWD="
|
||||
+ password
|
||||
)
|
||||
# cnxn = pyodbc.connect('DSN=sqldsn;')
|
||||
cursor = cnxn.cursor()
|
||||
return cursor
|
||||
Reference in New Issue
Block a user