diff --git a/actu_bdc_status/README.md b/actu_bdc_status/README.md new file mode 100644 index 0000000..384705e --- /dev/null +++ b/actu_bdc_status/README.md @@ -0,0 +1,109 @@ +# Actualisation de la BDC Status INPN à partir d'un dossier ZIP +## 1. Download BDC Status INPN +``` sh +# TAXREF V17.0 - Version du 15 novembre 2024 +wget https://inpn.mnhn.fr/docs-web/docs/download/232324 +``` + +## 2.Correction des formats de fichiers +La dernière version de l'INPN fournis 2 fichier dont 1 fichier Excel. +La mise à jour requière UNIQEMENT des fichiers CSV. +- Décompresser le ZIP +- Ouvrir le fichier Excel et enregistrer-le en CSV (encodage UTF8, séparateur virgule) +- Reformer le ZIP + +## 3. Intégration de la nouvelle BDC Statut +- Connectez-vous à votre serveur GéoNature et ouvrez un terminal python +``` sh +source geonature/backend/venv/bin/activate +geonature shell +``` +- Exécuter le script suivant en adaptant la variable `BASE_URL` (chemin d'accès vers le zip de la BDC Statut) +``` py +import os +import logging +from zipfile import ZipFile +import importlib.resources + +from apptax.taxonomie.commands.utils import truncate_bdc_statuts +from apptax.database import db +from apptax.taxonomie.commands.utils import ( + copy_from_csv, + refresh_taxref_vm, + populate_bdc_statut_cor_text_area, +) + +logger = logging.getLogger() + +BASE_URL = "/home/geonatureadmin/tmp" +zipfile = "BDC-Statuts-v17.zip" +status_types_file = "BDC-Statuts-v17/BDC_STATUTS_TYPES_17.csv" +status_file = "BDC-Statuts-v17/BDC_STATUTS_17.csv" + +truncate_bdc_statuts() +db.session.commit() + + +archive = ZipFile(os.path.join(BASE_URL, zipfile), "r") +with archive.open(status_file) as f: + logger.info("Insert BDC statuts…") + copy_from_csv( + f, + "bdc_statut", + dest_cols=( + "cd_nom", + "cd_ref", + "cd_sup", + "cd_type_statut", + "lb_type_statut", + "regroupement_type", + "code_statut", + "label_statut", + "rq_statut", + "cd_sig", + "cd_doc", + "lb_nom", + "lb_auteur", + "nom_complet_html", + "nom_valide_html", + "regne", + "phylum", + "classe", + "ordre", + "famille", + "group1_inpn", + "group2_inpn", + "lb_adm_tr", + "niveau_admin", + "cd_iso3166_1", + "cd_iso3166_2", + "full_citation", + "doc_url", + "thematique", + "type_value", + ), + ) + +logger.info("Populate BDC statuts…") +db.session.execute( + importlib.resources.read_text("apptax.migrations.data", "taxonomie_bdc_statuts.sql") +) + +populate_bdc_statut_cor_text_area(logger) +refresh_taxref_vm() +db.session.commit() + +exit() +``` + +## 4. Reformer les liens BDC Statut vs areas +``` sh +geonature taxref link-bdc-statut-to-areas +# Rendre accessible les status concernés par un département +# L'argument -d peut être répété dans le cas de plusieurs département +# Il est possible qu'il faille au préalable désactiver tous les status de la table bdc_statut_text +geonature taxref enable-bdc-statut-text --clean -d 38 +``` + + +