Spaces:
Sleeping
Sleeping
Update backend with high-quality catalog and fixes
Browse files- app/api/seed.py +11 -8
app/api/seed.py
CHANGED
|
@@ -165,15 +165,16 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 165 |
all_sub_cats[s["en"]] = sub_cat # Map both names to the same object
|
| 166 |
|
| 167 |
|
| 168 |
-
#
|
| 169 |
possible_paths = [
|
| 170 |
-
|
| 171 |
-
os.path.
|
| 172 |
-
|
|
|
|
|
|
|
| 173 |
os.path.abspath("kaggle/extra_products_vortex.json"),
|
|
|
|
| 174 |
os.path.abspath("real_products_200.json"),
|
| 175 |
-
"/app/kaggle/extra_products_vortex.json",
|
| 176 |
-
"/app/app/data/extra_products_vortex.json",
|
| 177 |
]
|
| 178 |
|
| 179 |
json_path = None
|
|
@@ -185,7 +186,7 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 185 |
if not json_path:
|
| 186 |
return AuthResponse(
|
| 187 |
isSuccess=False,
|
| 188 |
-
value={"message": "Source file
|
| 189 |
statusCode=404,
|
| 190 |
error="File not found"
|
| 191 |
)
|
|
@@ -332,8 +333,10 @@ async def seed_database(clear: bool = False, db: Session = Depends(get_db)):
|
|
| 332 |
isSuccess=True,
|
| 333 |
value={
|
| 334 |
"message": "تمت عملية المزامنة بنجاح",
|
| 335 |
-
"total_products":
|
| 336 |
"inserted_new": inserted_count,
|
|
|
|
|
|
|
| 337 |
},
|
| 338 |
statusCode=201,
|
| 339 |
)
|
|
|
|
| 165 |
all_sub_cats[s["en"]] = sub_cat # Map both names to the same object
|
| 166 |
|
| 167 |
|
| 168 |
+
# Prioritize the full catalog over the smaller sample
|
| 169 |
possible_paths = [
|
| 170 |
+
# 1. Packaged location (relative to this file)
|
| 171 |
+
os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "data", "extra_products_vortex.json")),
|
| 172 |
+
# 2. Docker /app location
|
| 173 |
+
"/app/app/data/extra_products_vortex.json",
|
| 174 |
+
# 3. Project root (typical for local dev)
|
| 175 |
os.path.abspath("kaggle/extra_products_vortex.json"),
|
| 176 |
+
# 4. Fallback to the 200 products sample
|
| 177 |
os.path.abspath("real_products_200.json"),
|
|
|
|
|
|
|
| 178 |
]
|
| 179 |
|
| 180 |
json_path = None
|
|
|
|
| 186 |
if not json_path:
|
| 187 |
return AuthResponse(
|
| 188 |
isSuccess=False,
|
| 189 |
+
value={"message": "Source file not found.", "searched": possible_paths},
|
| 190 |
statusCode=404,
|
| 191 |
error="File not found"
|
| 192 |
)
|
|
|
|
| 333 |
isSuccess=True,
|
| 334 |
value={
|
| 335 |
"message": "تمت عملية المزامنة بنجاح",
|
| 336 |
+
"total_products": len(products_data),
|
| 337 |
"inserted_new": inserted_count,
|
| 338 |
+
"skipped": skipped_count,
|
| 339 |
+
"source_file": os.path.basename(json_path)
|
| 340 |
},
|
| 341 |
statusCode=201,
|
| 342 |
)
|