inital = transfer git to git2
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import requests
|
||||
import json
|
||||
from general_functions import *
|
||||
cursor = create_cursor()
|
||||
|
||||
# -----------------------------------------------------------------
|
||||
|
||||
|
||||
BASE_URL = "https://api.tavasi.ir/list/"
|
||||
ADD_LIST_ROUTE = "project/add"
|
||||
ADD_ITEM_ROUTE = "subject/add"
|
||||
TITLE = "موضوعات قانونی"
|
||||
TYPE = 3
|
||||
ADD_LIST_QUERY = {"title": TITLE, "type": TYPE, "item_state": 1}
|
||||
GET_H = lambda x: x["HIERARCHY"]
|
||||
GET_F = lambda x: x["F_PARENTID"]
|
||||
projectid = 1
|
||||
|
||||
EXAMPLE_ADD_ITEM_QUERY = {
|
||||
"title": "",
|
||||
"projectid": projectid,
|
||||
"listtype": 0,
|
||||
"parent": 0,
|
||||
}
|
||||
|
||||
# print(requests.post(BASE_URL + ADD_LIST_ROUTE, data=ADD_LIST_QUERY, headers = HEADERS).text)
|
||||
|
||||
IDS_DICT = {}
|
||||
|
||||
query = """select * from dbo.lwtopic"""
|
||||
cursor.execute(query)
|
||||
|
||||
|
||||
result = []
|
||||
|
||||
while True:
|
||||
row = cursor.fetchone()
|
||||
if not row:
|
||||
break
|
||||
|
||||
HIERARCHY = row.HIERARCHY
|
||||
HIERARCHY = HIERARCHY.split(".")[-2]
|
||||
HIERARCHY = HIERARCHY.rjust(3, "0")
|
||||
|
||||
result.append(
|
||||
{
|
||||
"ID": int(row.ID),
|
||||
"CAPTION": row.CAPTION,
|
||||
"F_PARENTID": int(row.F_PARENTID) if row.F_PARENTID else 0,
|
||||
"HIERARCHY": HIERARCHY,
|
||||
}
|
||||
)
|
||||
# result = sorted(result, key=GET_F)
|
||||
result = sorted(result, key=GET_H)
|
||||
|
||||
for i in range(0, 195):
|
||||
number = 1
|
||||
for row in result:
|
||||
if not row:
|
||||
continue
|
||||
|
||||
try:
|
||||
parent = IDS_DICT[str(i)]['id']
|
||||
except KeyError:
|
||||
parent = 0
|
||||
|
||||
try:
|
||||
F_PARENTID = row["F_PARENTID"]
|
||||
except KeyError:
|
||||
F_PARENTID = -1
|
||||
# print('*'*20)
|
||||
# print(row)
|
||||
# print('#'*20)
|
||||
continue
|
||||
|
||||
if F_PARENTID == i : # or (i == 0 and row["F_PARENTID"] == None)
|
||||
ADD_ITEM_QUERY = {
|
||||
"title": row["CAPTION"],
|
||||
"projectid": projectid,
|
||||
"otherid": row["ID"],
|
||||
"childorder": number,
|
||||
"listtype": 0,
|
||||
"parent": parent,
|
||||
}
|
||||
number += 1
|
||||
result = requests.post(BASE_URL + ADD_ITEM_ROUTE, data=ADD_ITEM_QUERY, headers=HEADERS)
|
||||
|
||||
ID = json.loads(result.text)["data"][0]["id"]
|
||||
print(ID)
|
||||
IDS_DICT[str(row["ID"])] = {"id" : int(ID), 'title': row["CAPTION"]}
|
||||
|
||||
with open("list_LWTopic.json", 'w') as file:
|
||||
file.write(json.dumps(IDS_DICT))
|
||||
@@ -0,0 +1,106 @@
|
||||
import requests
|
||||
import pyodbc
|
||||
import json
|
||||
from decimal import Decimal
|
||||
from 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)
|
||||
@@ -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")
|
||||
Reference in New Issue
Block a user