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
,[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 '%
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)