Spaces:
Running
Running
Update supabase_utils.py
Browse files- supabase_utils.py +21 -19
supabase_utils.py
CHANGED
|
@@ -82,25 +82,27 @@ def save_law_to_supabase(law_json):
|
|
| 82 |
section_id = res_sec.data[0]["id"]
|
| 83 |
|
| 84 |
# إدراج المواد
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
| 89 |
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
|
| 106 |
print(f"✔ تم حفظ/تحديث جميع الأقسام والمواد والجداول للقانون: {title}")
|
|
|
|
| 82 |
section_id = res_sec.data[0]["id"]
|
| 83 |
|
| 84 |
# إدراج المواد
|
| 85 |
+
# إدراج المواد
|
| 86 |
+
for art in sec.get("articles", []):
|
| 87 |
+
article_number = int(art.get("number")) if art.get("number") else None
|
| 88 |
+
article_content = art.get("text", "")
|
| 89 |
+
article_tables = art.get("tables", [])
|
| 90 |
|
| 91 |
+
# UPSERT المواد بناءً على chapter_id و article_number مع id_law
|
| 92 |
+
res_art = (
|
| 93 |
+
supabase.table("articles")
|
| 94 |
+
.upsert(
|
| 95 |
+
{
|
| 96 |
+
"chapter_id": section_id,
|
| 97 |
+
"id_law": law_id, # ربط المادة بالقانون مباشرة
|
| 98 |
+
"article_number": article_number,
|
| 99 |
+
"content": article_content or "",
|
| 100 |
+
"tables": article_tables or [],
|
| 101 |
+
},
|
| 102 |
+
on_conflict=["chapter_id", "id_law", "article_number"], # المفتاح الفريد المركب للمواد
|
| 103 |
+
)
|
| 104 |
+
.execute()
|
| 105 |
+
)
|
| 106 |
+
article_id = res_art.data[0]["id"]
|
| 107 |
|
| 108 |
print(f"✔ تم حفظ/تحديث جميع الأقسام والمواد والجداول للقانون: {title}")
|