5633969d98
Carte Leaflet (annuaire Éducation nationale) + API PHP/MySQL : fiche établissement (effectifs, IPS, population INSEE, DPE ADEME), GED documents/photos, commentaires par groupe, gestion utilisateurs et politique de mots de passe. Imports opendata (effectifs, IPS, population, DPE, IRIS). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
45 lines
1.6 KiB
PHP
45 lines
1.6 KiB
PHP
<?php
|
|
/**
|
|
* Import des DPE des bâtiments tertiaires (ADEME) dans la table « dpe ».
|
|
* Source : data.ademe.fr, dataset « dpe01tertiaire » (DPE tertiaire depuis juillet 2021).
|
|
* API data-fair : .../lines (pagination par curseur « after / next »).
|
|
*
|
|
* ⚠ Le dataset n'a PAS d'identifiant école (UAI) : les bâtiments sont repérés
|
|
* par adresse BAN + géolocalisation. Le rattachement école↔DPE se fait
|
|
* ensuite par proximité géographique (cf. match_dpe.php).
|
|
*
|
|
* Usage :
|
|
* php import_dpe.php # importe tout (~532 000 DPE, plusieurs minutes)
|
|
* php import_dpe.php --dep=75 # n'importe qu'un département (test rapide)
|
|
*
|
|
* La logique est partagée avec l'endpoint web (api/dpe_lib.php).
|
|
*/
|
|
declare(strict_types=1);
|
|
require __DIR__ . '/api/dpe_lib.php';
|
|
|
|
function say(string $m): void { echo $m . "\n"; flush(); }
|
|
|
|
try {
|
|
$dep = null;
|
|
foreach ($argv ?? [] as $a) {
|
|
if (preg_match('/^--dep=(\w+)$/', $a, $m)) {
|
|
$dep = $m[1];
|
|
}
|
|
}
|
|
|
|
$pdo = db();
|
|
$n = dpe_import($pdo, $dep, static fn(string $m) => say(' … ' . $m));
|
|
|
|
$geo = (int) $pdo->query('SELECT COUNT(*) FROM dpe WHERE lat IS NOT NULL')->fetchColumn();
|
|
say("✔ dpe : $n DPE importés ($geo géolocalisés).");
|
|
say('→ Lancez maintenant « php match_dpe.php » pour rattacher les DPE aux établissements.');
|
|
say('🎉 Terminé.');
|
|
} catch (Throwable $e) {
|
|
if (isset($pdo) && $pdo->inTransaction()) {
|
|
$pdo->rollBack();
|
|
}
|
|
http_response_code(500);
|
|
say('!! ERREUR : ' . $e->getMessage());
|
|
exit(1);
|
|
}
|