Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| procedures:recuperation_et_integration_de_donnees_depuis_le_gbif [2026/02/02 14:11] – dmaillard | procedures:recuperation_et_integration_de_donnees_depuis_le_gbif [2026/02/03 07:59] (Version actuelle) – dmaillard | ||
|---|---|---|---|
| Ligne 73: | Ligne 73: | ||
| } | } | ||
| } | } | ||
| + | |||
| + | Autres configurations : | ||
| + | * [[Configuration Musée des Confluences]] | ||
| + | * [[Configuration Observations.org]] | ||
| Ligne 169: | Ligne 173: | ||
| WHERE id_dataset=3125; | WHERE id_dataset=3125; | ||
| + | Ces id_inaturalist sont ensuite utilisés dans R, avec le script suivant, pour récupérer les uuids des données dans iNaturalist, | ||
| + | |||
| + | fetch_inat_uuid <- function( | ||
| + | df, | ||
| + | id_col = " | ||
| + | uri_col = " | ||
| + | uuid_col = " | ||
| + | batch_size = 50, | ||
| + | sleep_sec = 1 | ||
| + | ) { | ||
| + | | ||
| + | library(httr) | ||
| + | library(jsonlite) | ||
| + | library(progress) | ||
| + | | ||
| + | # typer les id_inaturalist en integer | ||
| + | df[[id_col]] <- as.integer(trimws(df[[id_col]])) | ||
| + | | ||
| + | if (!uuid_col %in% names(df)) { | ||
| + | df[[uuid_col]] <- NA_character_ | ||
| + | } | ||
| + | | ||
| + | if (!uri_col %in% names(df)) { | ||
| + | df[[uri_col]] <- NA_character_ | ||
| + | } | ||
| + | | ||
| + | ids_to_fetch <- df[[id_col]][is.na(df[[uuid_col]])] | ||
| + | | ||
| + | batches <- split(ids_to_fetch, | ||
| + | | ||
| + | pb <- progress_bar$new( | ||
| + | format = " | ||
| + | total = length(batches), | ||
| + | clear = FALSE, | ||
| + | width = 60 | ||
| + | ) | ||
| + | | ||
| + | for (batch_ids in batches) { | ||
| + | | ||
| + | res <- try( | ||
| + | GET( | ||
| + | " | ||
| + | query = list( | ||
| + | id = paste(batch_ids, | ||
| + | fields=" | ||
| + | per_page = length(batch_ids) | ||
| + | ), | ||
| + | user_agent(" | ||
| + | ), | ||
| + | silent = TRUE | ||
| + | ) | ||
| + | | ||
| + | if (!inherits(res, | ||
| + | pb$tick() | ||
| + | Sys.sleep(sleep_sec * 2) | ||
| + | next | ||
| + | } | ||
| + | | ||
| + | json <- fromJSON( | ||
| + | content(res, | ||
| + | flatten = TRUE | ||
| + | ) | ||
| + | | ||
| + | if (length(json$results) > 0) { | ||
| + | uuids <- setNames( | ||
| + | json$results$uuid, | ||
| + | as.integer(json$results$id) | ||
| + | ) | ||
| + | | ||
| + | uris <- setNames( | ||
| + | json$results$uri, | ||
| + | as.integer(json$results$id) | ||
| + | ) | ||
| + | | ||
| + | idx <- match(as.integer(names(uuids)), | ||
| + | df[[uuid_col]][idx] <- uuids | ||
| + | | ||
| + | idx <- match(as.integer(names(uris)), | ||
| + | df[[uri_col]][idx] <- uris | ||
| + | } | ||
| + | | ||
| + | pb$tick() | ||
| + | Sys.sleep(sleep_sec) | ||
| + | } | ||
| + | | ||
| + | return(df) | ||
| + | } | ||
| + | |||
| + | |||
| + | |||
| + | inaturalist_uuids <- fetch_inat_uuid( | ||
| + | inaturalist_ids, | ||
| + | id_col | ||
| + | uuid_col = " | ||
| + | batch_size = 50, | ||
| + | sleep_sec = 1 | ||
| + | ) | ||
| + | | ||
| + | Ces résultats sont ensuite exportés de R, importés dans la base de données postgresql dans une table pinv_gbif.cor_uuid_inaturalist, | ||
| + | | ||
| ==== Postgresql : Insérer ou actualiser les données en synthèse ==== | ==== Postgresql : Insérer ou actualiser les données en synthèse ==== | ||