Skip to main content

Passage en production - script d'éxécution des fiches

Altéris permet en un seul clic de préparer chaque dossier Obsidian d'étude territoriale : 

- les fiches de référence sont dans le NAS dans le dossier Alteris - "Z:\Production\Obsidian_Alteris\Indicateurs"

- le script Python AL_04_Deploiement_xxx_Flat.py les duplique dans le dossier etude en ajoutant les tags INSEE relatifs au territoire client (exemple - AL_04_Deploiement_La_Ciotat_Flat.py - 13028) permettant de lier le Wiki et Obsidian

Script de passage en production pour la Ciotat (13028)

import os
import re

# --- CONFIGURATION DE L'ÉTUDE ---
NOM_TERRITOIRE = "La Ciotat"
CODE_INSEE = "13028"

# --- CHEMINS (Structure Profonde NAS) ---
src_dir = r"Z:\Production\Obsidian_Alteris\Indicateurs"
# Chemin spécifique selon votre nomenclature Région/Département/EPCI/Commune
dest_dir = r"Z:\Production\Etudes\Region\93\13\200054807\13028"

wiki_url = "https://votre-wiki-alteris.fr/search?term="

print(f"--- DÉPLOIEMENT FLAT : {NOM_TERRITOIRE} ---")

if not os.path.exists(src_dir):
    print(f"ERREUR : Source introuvable : {src_dir}")
else:
    if not os.path.exists(dest_dir):
        os.makedirs(dest_dir)

    count = 0
    # On parcourt la source (qui a des sous-dossiers)...
    for root, dirs, files in os.walk(src_dir):
        for file in files:
            if file.endswith(".md") and not file.startswith("00_"):
                src_file = os.path.join(root, file)
                
                with open(src_file, 'r', encoding='utf-8') as f:
                    content = f.read()

                # Mise à jour des métadonnées pour La Ciotat
                new_content = re.sub(r"Territoire:.*", f"Territoire: {NOM_TERRITOIRE}", content)
                new_content = re.sub(r"Code_INSEE:.*", f'Code_INSEE: "{CODE_INSEE}"', new_content)
                new_content = re.sub(r"Statut:.*", "Statut: A rédiger", new_content)

                # Ajout du lien Territorial sous le lien Méthodo
                territory_link = f"📍 **Dossier Territorial :** [{NOM_TERRITOIRE}]({wiki_url}[tag:{CODE_INSEE}])\n"
                if "Lien Wiki Méthodo" in new_content:
                    new_content = new_content.replace("---", "---\n" + territory_link, 1)

                # ÉCRITURE À LA RACINE du dossier destination
                # Le nom du fichier contient déjà l'ID grâce à AL_03
                target_file = os.path.join(dest_dir, file)
                
                with open(target_file, 'w', encoding='utf-8') as f:
                    f.write(new_content)
                count += 1

    print(f"SUCCÈS : {count} fiches déployées à plat dans : {dest_dir}")