MMOON commited on
Commit
313bd6b
·
verified ·
1 Parent(s): 7fad450

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -20
app.py CHANGED
@@ -12,6 +12,7 @@ import plotly.graph_objects as go
12
  import os
13
  import json
14
  from tqdm import tqdm
 
15
 
16
  # Configuration du logging
17
  logging.basicConfig(
@@ -154,12 +155,16 @@ class PesticideDataFetcher:
154
  # Don't load details here. Use the cache.
155
  # self._load_substance_details(substance_id) # Removed
156
 
157
- url = data.get("nextLink")
 
 
 
 
 
 
158
  logger.info(f"Substances loaded so far: {substances_loaded}")
159
- if url:
160
- data = self.fetch_data(url) # No params needed for nextLink
161
- if not data:
162
- break
163
  if self.use_cache:
164
  self._save_caches()
165
 
@@ -246,12 +251,14 @@ class PesticideDataFetcher:
246
  products_loaded += 1
247
  all_products.append(product)
248
 
249
- url = data.get("nextLink") if isinstance(data, dict) else None
 
 
 
 
 
 
250
  logger.info(f"Products retrieved so far: {products_loaded}")
251
- if url:
252
- data = self.fetch_data(url) # No params needed for nextLink
253
- if not data:
254
- break
255
 
256
  if self.use_cache:
257
  self._save_caches()
@@ -279,11 +286,13 @@ class PesticideDataFetcher:
279
  logger.error(f"Error retrieving MRLs: {data.get('error', 'No info')}")
280
  break
281
  mrls.extend(data.get("value", []))
282
- url = data.get("nextLink")
283
- if url:
284
- data = self.fetch_data(url) # No params needed for nextLink
285
- if not data:
286
- break
 
 
287
 
288
  self._mrl_cache[product_id] = mrls
289
  if self.use_cache:
@@ -315,13 +324,15 @@ class PesticideDataFetcher:
315
  break
316
 
317
  all_mrls.extend(data.get("value", []))
318
- url = data.get("nextLink")
319
- if url:
320
- data = self.fetch_data(url) # No params needed for nextLink
321
- if not data:
322
- break
 
323
  logger.info(f"MRLs retrieved for substance {substance_id}: {len(all_mrls)}")
324
  return all_mrls
 
325
  def format_date(self, date_str: Optional[str]) -> str:
326
  """Formats an ISO date string into a readable format."""
327
  if not date_str:
 
12
  import os
13
  import json
14
  from tqdm import tqdm
15
+ import urllib.parse # IMPORTANT: For joining URLs
16
 
17
  # Configuration du logging
18
  logging.basicConfig(
 
155
  # Don't load details here. Use the cache.
156
  # self._load_substance_details(substance_id) # Removed
157
 
158
+ next_link = data.get("nextLink")
159
+ if next_link:
160
+ # Correctly join the BASE_URL with the relative nextLink
161
+ url = urllib.parse.urljoin(self.BASE_URL, next_link)
162
+ params = None # IMPORTANT: Don't send params again!
163
+ else:
164
+ url = None
165
  logger.info(f"Substances loaded so far: {substances_loaded}")
166
+
167
+
 
 
168
  if self.use_cache:
169
  self._save_caches()
170
 
 
251
  products_loaded += 1
252
  all_products.append(product)
253
 
254
+ next_link = data.get("nextLink") if isinstance(data, dict) else None #Get nextLink
255
+ if next_link:
256
+ # Correctly join the BASE_URL with the relative nextLink
257
+ url = urllib.parse.urljoin(self.BASE_URL, next_link)
258
+ params = None # IMPORTANT: Don't send params again!
259
+ else:
260
+ url = None
261
  logger.info(f"Products retrieved so far: {products_loaded}")
 
 
 
 
262
 
263
  if self.use_cache:
264
  self._save_caches()
 
286
  logger.error(f"Error retrieving MRLs: {data.get('error', 'No info')}")
287
  break
288
  mrls.extend(data.get("value", []))
289
+ next_link = data.get("nextLink")
290
+ if next_link:
291
+ url = urllib.parse.urljoin(self.BASE_URL, next_link)
292
+ params = None
293
+ else:
294
+ url = None
295
+
296
 
297
  self._mrl_cache[product_id] = mrls
298
  if self.use_cache:
 
324
  break
325
 
326
  all_mrls.extend(data.get("value", []))
327
+ next_link = data.get("nextLink")
328
+ if next_link:
329
+ url = urllib.parse.urljoin(self.BASE_URL, next_link)
330
+ params = None
331
+ else:
332
+ url = None
333
  logger.info(f"MRLs retrieved for substance {substance_id}: {len(all_mrls)}")
334
  return all_mrls
335
+
336
  def format_date(self, date_str: Optional[str]) -> str:
337
  """Formats an ISO date string into a readable format."""
338
  if not date_str: