refactor to auto import

This commit is contained in:
hsafaei
2025-01-13 10:50:00 +03:30
parent e991cc84cb
commit d819408715
35 changed files with 3832 additions and 1504 deletions
+111
View File
@@ -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)