Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# Fichier: app.py
|
| 2 |
|
| 3 |
# ===================================================================================
|
| 4 |
-
# WAHIS SCRAPER - VERSION FINALE AVEC
|
| 5 |
# ===================================================================================
|
| 6 |
|
| 7 |
import gradio as gr
|
|
@@ -79,25 +79,19 @@ class WAHISScraper:
|
|
| 79 |
)
|
| 80 |
self.log("📊 Réponse JSON reçue avec succès !")
|
| 81 |
|
| 82 |
-
# CORRECTION :
|
| 83 |
# -----------------------------------------------------------------
|
| 84 |
self.log("🔍 Analyse de la structure de la réponse JSON...")
|
| 85 |
report_list = []
|
| 86 |
if isinstance(api_response_json, dict):
|
| 87 |
self.log(f" -> La réponse est un dictionnaire. Clés: {list(api_response_json.keys())}")
|
| 88 |
-
|
|
|
|
| 89 |
for key in possible_keys:
|
| 90 |
if key in api_response_json and isinstance(api_response_json[key], list):
|
| 91 |
report_list = api_response_json[key]
|
| 92 |
self.log(f" -> Liste trouvée dans la clé '{key}'.")
|
| 93 |
break
|
| 94 |
-
if not report_list and 'grid' in api_response_json and isinstance(api_response_json.get('grid'), dict) and 'data' in api_response_json['grid']:
|
| 95 |
-
report_list = api_response_json['grid']['data']
|
| 96 |
-
self.log(" -> Liste trouvée dans la structure imbriquée 'grid' -> 'data'.")
|
| 97 |
-
|
| 98 |
-
elif isinstance(api_response_json, list):
|
| 99 |
-
self.log(" -> La réponse est directement une liste.")
|
| 100 |
-
report_list = api_response_json
|
| 101 |
# -----------------------------------------------------------------
|
| 102 |
|
| 103 |
if report_list and isinstance(report_list, list):
|
|
@@ -108,9 +102,6 @@ class WAHISScraper:
|
|
| 108 |
return "\n".join(self.logs), df, excel_path, json_path
|
| 109 |
else:
|
| 110 |
self.log("❌ La structure JSON ne contient pas de liste de rapports identifiable.")
|
| 111 |
-
raw_json_str = json.dumps(api_response_json)
|
| 112 |
-
if len(raw_json_str) < 1000:
|
| 113 |
-
self.log(f" -> Contenu JSON brut : {raw_json_str}")
|
| 114 |
|
| 115 |
except Exception as e:
|
| 116 |
self.log(f"❌ Une erreur critique est survenue.")
|
|
|
|
| 1 |
# Fichier: app.py
|
| 2 |
|
| 3 |
# ===================================================================================
|
| 4 |
+
# WAHIS SCRAPER - VERSION FINALE AVEC LA CLÉ DE DONNÉES CORRECTE
|
| 5 |
# ===================================================================================
|
| 6 |
|
| 7 |
import gradio as gr
|
|
|
|
| 79 |
)
|
| 80 |
self.log("📊 Réponse JSON reçue avec succès !")
|
| 81 |
|
| 82 |
+
# CORRECTION FINALE : Ajouter 'list' aux clés possibles
|
| 83 |
# -----------------------------------------------------------------
|
| 84 |
self.log("🔍 Analyse de la structure de la réponse JSON...")
|
| 85 |
report_list = []
|
| 86 |
if isinstance(api_response_json, dict):
|
| 87 |
self.log(f" -> La réponse est un dictionnaire. Clés: {list(api_response_json.keys())}")
|
| 88 |
+
# LA CORRECTION EST ICI : Ajout de 'list' en première position
|
| 89 |
+
possible_keys = ['list', 'data', 'results', 'items', 'events']
|
| 90 |
for key in possible_keys:
|
| 91 |
if key in api_response_json and isinstance(api_response_json[key], list):
|
| 92 |
report_list = api_response_json[key]
|
| 93 |
self.log(f" -> Liste trouvée dans la clé '{key}'.")
|
| 94 |
break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# -----------------------------------------------------------------
|
| 96 |
|
| 97 |
if report_list and isinstance(report_list, list):
|
|
|
|
| 102 |
return "\n".join(self.logs), df, excel_path, json_path
|
| 103 |
else:
|
| 104 |
self.log("❌ La structure JSON ne contient pas de liste de rapports identifiable.")
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
except Exception as e:
|
| 107 |
self.log(f"❌ Une erreur critique est survenue.")
|