paln tcode

This commit is contained in:
hsafaei
2025-06-07 15:17:39 +03:30
parent b2ae4b810c
commit 53764fd4ef
6 changed files with 642 additions and 81 deletions
+36 -4
View File
@@ -20,14 +20,44 @@ def read_excel_data(file_path ):
row["META"] = row.get("توضیحات", "")
return data
def insert_project():
def insert_project(title, id=''):
projectid = 8 # فرض کنید projectid ثابت است
return projectid
def insertProejct(title, id=''):
# ایجاد فهرست جدید
url = "project/add"
item = {
"id": id,
"title": title,
"type": 3,
"item_state": 1,
"ispublic" : 1,
}
result = requests.post(BASE_URL + 'list/' + url, data=item, headers = HEADERS)
res = json.loads(result.text)
if result.status_code == 200 :
# print(result.text)
New_ID = res["data"]["id"]
print(str('project added =' + str(New_ID)))
projectid = New_ID
return projectid
else :
New_ID = res["data"]["id"]
print(str('project exist=' + str(New_ID)))
projectid = New_ID
# print(res)
return projectid
def process_excel_data(file_path, send_to_server=True):
data = read_excel_data(file_path)
data = sorted(data, key=lambda x: x["ID"])
projectid = insert_project()
projectid = insert_project('کدهای تنقیح 50 باب', 8)
id_counter = 1 # برای fake_id
local_id_map = {} # برای نگه‌داشتن ID ساختگی در حالت تست
output_data = [] # لیستی برای ذخیره خروجی نهایی
@@ -36,6 +66,8 @@ def process_excel_data(file_path, send_to_server=True):
row_id = row["ID"]
meta = row.get("META", "")
insertProejct('پلان ' + caption, 100+row_id)
# در حالت تست، parent_id از local map خونده میشه
payload = {
"title": caption,
@@ -66,7 +98,7 @@ def process_excel_data(file_path, send_to_server=True):
fake_id = id_counter
local_id_map[row_id] = fake_id
id_counter += 1
print(f"🧪 TEST MODE: Would insert => {payload} | Fake ID: {fake_id}")
# print(f"🧪 TEST MODE: Would insert => {payload} | Fake ID: {fake_id}")
output_data.append(payload)
file_name = "mmm1.json"
with open(file_name, "w", encoding="utf-8") as file:
@@ -76,4 +108,4 @@ def process_excel_data(file_path, send_to_server=True):
if __name__ == "__main__":
file_path = "data/کدهای 50 گانه.xlsx"
process_excel_data(file_path ,send_to_server=True ) # False for test
process_excel_data(file_path ,send_to_server=False ) # False for test