اخرین تغییرات برای 50 کد

This commit is contained in:
Mehdi104797
2025-05-27 07:26:26 +03:30
parent 5a62918218
commit 969545e253
6 changed files with 1633 additions and 48 deletions
+28 -25
View File
@@ -9,9 +9,9 @@ from general_functions import *
ADD_ITEM_ROUTE = "subject/add"
# TITLE = ""
def read_excel_data(file_path ,sheet_name):
df = pd.read_excel(file_path , sheet_name=sheet_name)
df.fillna("", inplace=True)
data = df.to_dict(orient="records")
text_normal = TextNormalizer()
@@ -22,20 +22,22 @@ def read_excel_data(file_path ,sheet_name):
row["CODE"] = row.get("کد", "")
return data
def insert_project():
# ADD_LIST_QUERY = {
# "title": TITLE,
# "type": 3,
# "item_state": 1,
# "ispublic": 1,
# }
# def insert_project():
# requests.post(BASE_URL + 'list/' + ADD_LIST_ROUTE, data=ADD_LIST_QUERY, headers=HEADERS)
projectid = 7 # فرض کنید projectid ثابت است
return projectid
# projectid = 7 # فرض کنید projectid ثابت است
# return projectid
def insert_project(sheet_name):
json_file = 'کدهای 50 گانه.json'
with open(json_file, 'r', encoding='utf-8') as f:
data = json.load(f)
for row in data:
if row.get("title") == sheet_name:
base_id = row.get("otherid", 0)
return base_id + 100 # افزایش ۱۰۰ واحدی
print(f"❌ Sheet name '{sheet_name}' not found in JSON data.")
return None
def insert_real(rows, projectid, IDS_DICT, childs):
def insert_real(rows, projectid, IDS_DICT, childs,otherid):
remains = []
for row in rows:
@@ -65,6 +67,7 @@ def insert_real(rows, projectid, IDS_DICT, childs):
ADD_ITEM_QUERY = {
"title": caption,
"projectid": projectid,
"otherid": otherid,
"meta": row.get("CODE", ""),
"childorder": number,
"listtype": 0,
@@ -93,9 +96,6 @@ def insert_real(rows, projectid, IDS_DICT, childs):
return remains
def process_excel_data(file_path , sheet_name):
data = read_excel_data(file_path , sheet_name)
data = sorted(data, key=lambda x: x["ID"])
@@ -103,28 +103,31 @@ def process_excel_data(file_path , sheet_name):
IDS_DICT = {}
childs = {}
projectid = insert_project()
projectid = insert_project(sheet_name)
otherid = insert_project(sheet_name)-100
if not projectid:
return
print("🚀 شروع درج داده‌ها")
remains = insert_real(data, projectid, IDS_DICT, childs)
remains = insert_real(data, projectid, IDS_DICT, childs , otherid)
count = 1
while remains and count < 3:
print(f"\n🔁 تلاش مجدد {count}: باقی‌مانده {len(remains)} آیتم")
remains = insert_real(remains, projectid, IDS_DICT, childs)
remains = insert_real(remains, projectid, IDS_DICT, childs ,otherid)
count += 1
output_file = "real_ids_farhang_honar.json"
with open(output_file, "w", encoding="utf-8") as file:
json_file_path = f'{sheet_name}.json'
with open(json_file_path, "w", encoding="utf-8") as file:
json.dump(IDS_DICT, file, ensure_ascii=False, indent=4)
print(f"\n✅ تمام داده‌ها ثبت شدند و در {output_file} ذخیره شدند.")
print(f"\n✅ تمام داده‌ها ثبت شدند و در {sheet_name} ذخیره شدند.")
if __name__ == "__main__":
file_path = "H:\\personal\\Plan.xlsx"
sheet_name = 'آموزش و پرورش'
# sheet_name = 'مناطق آزاد'
file_path = "data/Plan.xlsx"
# sheet_name = 'آموزش و پرورش'
sheet_name = 'مناطق آزاد و ویژه اقتصادی'
# sheet_name = 'فرهنگ و هنر'
process_excel_data(file_path , sheet_name)