From c366f8f9e8528fe8e1a2cc5e627e2d62aad0e5fa Mon Sep 17 00:00:00 2001 From: devthejo Date: Sun, 8 Mar 2026 15:01:41 +0100 Subject: [PATCH] feat(dae): complete pipeline --- package.json | 1 + scripts/dae/download-geodae.mjs | 45 +++++++++++++++++++++++++++++++++ scripts/dae/package.json | 3 ++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 scripts/dae/download-geodae.mjs diff --git a/package.json b/package.json index 6835013..74a3b35 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "open:deeplink": "npx uri-scheme open --android", "screenshot:ios": "scripts/screenshot-ios.sh", "screenshot:android": "scripts/screenshot-android.sh", + "dae:download": "yarn --cwd scripts/dae download", "dae:json-to-csv": "yarn --cwd scripts/dae json-to-csv", "dae:csv-to-db": "yarn --cwd scripts/dae csv-to-db", "dae:build": "yarn --cwd scripts/dae build" diff --git a/scripts/dae/download-geodae.mjs b/scripts/dae/download-geodae.mjs new file mode 100644 index 0000000..1f0fa7e --- /dev/null +++ b/scripts/dae/download-geodae.mjs @@ -0,0 +1,45 @@ +#!/usr/bin/env node + +// Download the GeoDAE JSON file from data.gouv.fr +// Source: https://www.data.gouv.fr/datasets/geodae-base-nationale-des-defibrillateurs +// Resource ID: 86ea48a0-dd94-4a23-b71c-80d3041d7db2 + +import { createWriteStream } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; +import { pipeline } from "node:stream/promises"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); + +const RESOURCE_ID = "86ea48a0-dd94-4a23-b71c-80d3041d7db2"; +const DOWNLOAD_URL = `https://www.data.gouv.fr/api/1/datasets/r/${RESOURCE_ID}`; +const OUTPUT = join(__dirname, "geodae.json"); + +async function download() { + console.log(`Downloading GeoDAE data from data.gouv.fr ...`); + console.log(`URL: ${DOWNLOAD_URL}`); + + const response = await fetch(DOWNLOAD_URL, { redirect: "follow" }); + + if (!response.ok) { + throw new Error( + `Download failed: ${response.status} ${response.statusText}` + ); + } + + const contentLength = response.headers.get("content-length"); + if (contentLength) { + console.log( + `File size: ${(parseInt(contentLength, 10) / 1024 / 1024).toFixed(1)} MB` + ); + } + + await pipeline(response.body, createWriteStream(OUTPUT)); + + console.log(`Saved to ${OUTPUT}`); +} + +download().catch((err) => { + console.error(err.message); + process.exit(1); +}); diff --git a/scripts/dae/package.json b/scripts/dae/package.json index fc4b49d..3cacb06 100644 --- a/scripts/dae/package.json +++ b/scripts/dae/package.json @@ -5,10 +5,11 @@ "type": "module", "packageManager": "yarn@4.5.3", "scripts": { + "download": "node download-geodae.mjs", "json-to-csv": "node geodae-to-csv.js", "csv-to-db": "node csv-to-sqlite.mjs --input geodae.csv --output ../../src/assets/db/geodae.db", "csv-to-db:semicolon": "node csv-to-sqlite.mjs --input geodae.csv --output ../../src/assets/db/geodae.db --delimiter ';'", - "build": "yarn json-to-csv && yarn csv-to-db" + "build": "yarn download && yarn json-to-csv && yarn csv-to-db" }, "dependencies": { "better-sqlite3": "^11.7.0",