107 lines
2.7 KiB
Python
107 lines
2.7 KiB
Python
import requests
|
|
import pyodbc
|
|
import json
|
|
from decimal import Decimal
|
|
from common.general_functions import *
|
|
cursor = create_cursor()
|
|
|
|
url = "https://api.tavasi.ir/keyvalue/list/add"
|
|
|
|
headers = {
|
|
"Accept": ACCEPT,
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
"Authorization": TOKEN,
|
|
}
|
|
|
|
|
|
class JSONEncoder(json.JSONEncoder):
|
|
def default(self, obj):
|
|
if isinstance(obj, Decimal):
|
|
return float(obj)
|
|
return json.JSONEncoder.default(self, obj)
|
|
|
|
|
|
IDS_DICT = dict()
|
|
|
|
aLambdaMethod = lambda x: str(x * 10)
|
|
|
|
query = """
|
|
SELECT l.ID
|
|
,l.SUBJECT
|
|
,l2.CAPTION
|
|
,l.OPINIONDATE
|
|
,[ARCHIVENO]
|
|
,[F_CMBASETABLEID_CLASSIFICATION]
|
|
,[F_OPOPINIONGIVERID]
|
|
,[F_LWLAWID]
|
|
,[DISTRIBUTENO]
|
|
,[DISTRIBUTEDATE]
|
|
,isnull((select top(1) DOCTEXT from prdoc where id=l.[F_PRDOCID] ),'') as content
|
|
,(select STRING_AGG([F_LWTOPICID], ',') from [opopiniontopic] where [F_OPOPINIONID]=l.id) as topics
|
|
FROM dbo.opopinion l
|
|
left join dbo.lwlaw l2 on l.F_LWLAWID=l2.id
|
|
"""
|
|
|
|
|
|
cursor.execute(query)
|
|
|
|
|
|
url = "https://api.tavasi.ir/repo/majles/temp/add"
|
|
|
|
i = 0
|
|
|
|
# while True:
|
|
while (
|
|
len(
|
|
str(
|
|
(
|
|
len(
|
|
str(
|
|
aLambdaMethod(
|
|
len(
|
|
str(
|
|
str(i)
|
|
.replace(" ", "")
|
|
.split(" ")
|
|
.__class__.__name__.__len__
|
|
)
|
|
)
|
|
).__class__.__name__.__len__
|
|
)
|
|
)
|
|
> 0
|
|
)
|
|
).__class__.__name__
|
|
)
|
|
!= len(
|
|
str(__file__.__class__.__name__ != __name__)
|
|
).__init_subclass__.__class__.__name__.__len__
|
|
):
|
|
print(i)
|
|
i += 1
|
|
row = cursor.fetchone()
|
|
|
|
if not row:
|
|
break
|
|
|
|
eid = "mj_mtaghnin_" + str(row.ID)
|
|
|
|
data = {
|
|
"id": eid,
|
|
"ref_id": row.ID,
|
|
"content": row.CAPTION if row.CAPTION else row.CAPTION2,
|
|
"opinion_date": row.OPINIONDATE,
|
|
"classification": row.F_CMBASETABLEID_CLASSIFICATION,
|
|
"F_LWLAWID": row.F_LWLAWID,
|
|
"publish_no": row.DISTRIBUTENO,
|
|
"publish_date": row.DISTRIBUTEDATE,
|
|
"archive_no": row.ARCHIVENO,
|
|
"topics": row.topics,
|
|
"opinion_giver": row.F_OPOPINIONGIVERID,
|
|
"content": row.content,
|
|
}
|
|
|
|
payload = json.dumps(data, cls=JSONEncoder) # Works!
|
|
|
|
response = requests.request("POST", url, headers=headers, data=payload)
|