This commit is contained in:
hsafaei
2025-09-02 11:59:08 +03:30
parent 69eb568cf7
commit cfe3cff77c
17 changed files with 1 additions and 202 deletions
+77
View File
@@ -0,0 +1,77 @@
import pyodbc
import requests
from html import escape
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)
# cursor.execute("SELECT @@VERSION;")
# dict_cmbasetable = json.loads(open("list_cmbasetable.json").read())
query = """select l.id as ref_id,l.CAPTION as title
,isnull(t.caption,'') as type1
,isnull(ls.caption,'') as status1
,isnull(lt.caption,'') as tanghih
,isnull(co.CAPTION,'') as ts_ref
,isnull([EXPIREDATE],'') as exp_date
,isnull([majlesno],'') as majlesno
,isnull(APPROVEDATE,'') as ts_date
,isnull([APPROVEDATELast],'') as ts_date_last
,isnull((select top(1) txt from lwlawtext where f_lwlawid=l.id order by f_lwphaseid desc ),'') as content
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwexecutor] where F_LWLAWID=l.id) as exceuter_CMORGANIZATION
,(select STRING_AGG(F_CMORGANIZATIONID, ',') from [lwreceiver] where F_LWLAWID=l.id) as receiver_CMORGANIZATION
from lwlaw l
left join lwlawtype t on l.[f_lwlawtypeid]=t.id
left join lwlawstatus ls on l.[f_lwlawstatusid] = ls.id
left join lwlawtanghih lt on l.[f_lwlawtanghihid] = lt.id
left join cmorganization co on l.[F_CMORGANIZATIONIDApprover]=co.id"""
cursor.execute(query)
url = "https://api.tavasi.ir/repo/majles/temp/add"
headers = HEADERS
i = 1
while 1:
print(i)
i = i + 1
row = cursor.fetchone()
if not row:
break
# if row.ref_id > 1000:
# break
eid = "mj_mtaghnin_" + str(row.ref_id)
data = {
"eid": eid,
"exceuter_CMORGANIZATION": row.exceuter_CMORGANIZATION,
"receiver_CMORGANIZATION": row.receiver_CMORGANIZATION,
}
payload = json.dumps(data, cls=JSONEncoder) # Works!
response = requests.request("POST", url, headers=headers, data=payload)
# print(response.text)
# print(row.txt)
cursor.close()
cnxn.close()
print("end success")