Spaces:
Runtime error
Runtime error
Update import_prestashop.py
Browse files- import_prestashop.py +12 -10
import_prestashop.py
CHANGED
@@ -7,7 +7,7 @@ PRESTASHOP_API_KEY = "SI4TMK8J6Z38DJ4SB29GAMUQP7MF9EQI"
|
|
7 |
def fetch_prestashop_products():
|
8 |
"""Récupère les produits depuis PrestaShop avec gestion d'erreurs améliorée"""
|
9 |
headers = {"Authorization": f"Basic {PRESTASHOP_API_KEY}", "Accept": "application/json"}
|
10 |
-
|
11 |
try:
|
12 |
print("🔍 Test de connexion à l'API PrestaShop...")
|
13 |
response = requests.get(PRESTASHOP_API_URL, headers=headers, timeout=5)
|
@@ -17,8 +17,7 @@ def fetch_prestashop_products():
|
|
17 |
return []
|
18 |
|
19 |
data = response.json()
|
20 |
-
|
21 |
-
print("🔍 Données brutes reçues de PrestaShop:", json.dumps(data, indent=2))
|
22 |
|
23 |
products = data.get("products", [])
|
24 |
|
@@ -28,12 +27,15 @@ def fetch_prestashop_products():
|
|
28 |
|
29 |
structured_products = []
|
30 |
for product in products:
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
37 |
|
38 |
return structured_products
|
39 |
|
@@ -44,4 +46,4 @@ def fetch_prestashop_products():
|
|
44 |
except requests.exceptions.RequestException as e:
|
45 |
print(f"❌ Erreur API PrestaShop : {e}")
|
46 |
|
47 |
-
return []
|
|
|
7 |
def fetch_prestashop_products():
|
8 |
"""Récupère les produits depuis PrestaShop avec gestion d'erreurs améliorée"""
|
9 |
headers = {"Authorization": f"Basic {PRESTASHOP_API_KEY}", "Accept": "application/json"}
|
10 |
+
|
11 |
try:
|
12 |
print("🔍 Test de connexion à l'API PrestaShop...")
|
13 |
response = requests.get(PRESTASHOP_API_URL, headers=headers, timeout=5)
|
|
|
17 |
return []
|
18 |
|
19 |
data = response.json()
|
20 |
+
print("🔍 Données brutes reçues de PrestaShop:", json.dumps(data, indent=2)) # Debugging
|
|
|
21 |
|
22 |
products = data.get("products", [])
|
23 |
|
|
|
27 |
|
28 |
structured_products = []
|
29 |
for product in products:
|
30 |
+
try:
|
31 |
+
structured_products.append({
|
32 |
+
"title": product.get("name", {}).get("language", [{}])[0].get("value", "Produit inconnu"),
|
33 |
+
"category": product.get("category", "Non classé"),
|
34 |
+
"price": float(product.get("price", 0.0)),
|
35 |
+
"id": product.get("id", "N/A")
|
36 |
+
})
|
37 |
+
except Exception as e:
|
38 |
+
print(f"⚠️ Erreur lors du traitement d'un produit: {e}")
|
39 |
|
40 |
return structured_products
|
41 |
|
|
|
46 |
except requests.exceptions.RequestException as e:
|
47 |
print(f"❌ Erreur API PrestaShop : {e}")
|
48 |
|
49 |
+
return []
|