@@ -191,16 +191,41 @@ def data_01(self):
191191 Message with the results or recommendations to improve this indicator
192192 """
193193 # Search and download GBIF data
194- try :
195- auth = (
196- self .config ["gbif" ]["api_mail" ],
197- self .config ["gbif" ]["api_user" ],
198- self .config ["gbif" ]["api_pass" ],
199- )
200- download_dict = gbif_doi_download (self .item_id , auth = auth )
201- except Exception as e :
202- logger .debug (e )
203- return (0 , "" )
194+ short_name = None
195+ for key , e in self .metadata [
196+ self .metadata ["qualifier" ] == "alternateIdentifier"
197+ ].iterrows ():
198+ if "ipt.gbif" in e ["text_value" ]:
199+ short_name = e ["text_value" ].split ("r=" , 1 )[1 ]
200+ url = "https://ipt.gbif.es/archive.do?r=" + short_name
201+ logger .debug (url )
202+ # Descarga los datos del conjunto
203+ logger .debug ("Descarga" )
204+ if short_name is not None :
205+ download_dict = {}
206+ download_dict ["path" ] = f"/FAIR_eva/plugins/gbif/downloads/{ short_name } .zip"
207+ try :
208+ os .makedirs ("/FAIR_eva/plugins/gbif/downloads/" , exist_ok = True )
209+ with open (download_dict ["path" ], "wb" ) as f :
210+ # Itera sobre los bloques del archivo descargado
211+ for data in requests .get (
212+ url ,
213+ stream = True ,
214+ ).iter_content (chunk_size = 1024 ):
215+ f .write (data )
216+ except Exception as e :
217+ logger .debug (f"ERROR Downloading Data: { e } " )
218+ if not os .path .exists (download_dict ["path" ]):
219+ try :
220+ auth = (
221+ self .config ["gbif" ]["api_mail" ],
222+ self .config ["gbif" ]["api_user" ],
223+ self .config ["gbif" ]["api_pass" ],
224+ )
225+ download_dict = gbif_doi_download (self .item_id , auth = auth )
226+ except Exception as e :
227+ logger .debug (e )
228+ return (0 , "" )
204229
205230 # Calculates ICA
206231 logger .debug ("Calculo ICA" )
0 commit comments