import json import requests from common.config_base import * import requests from bs4 import BeautifulSoup from html import escape import json from decimal import Decimal import datetime from common.config_base import * from common.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)