feat(dae): complete pipeline
This commit is contained in:
parent
4091f3a44f
commit
c366f8f9e8
3 changed files with 48 additions and 1 deletions
|
|
@ -52,6 +52,7 @@
|
||||||
"open:deeplink": "npx uri-scheme open --android",
|
"open:deeplink": "npx uri-scheme open --android",
|
||||||
"screenshot:ios": "scripts/screenshot-ios.sh",
|
"screenshot:ios": "scripts/screenshot-ios.sh",
|
||||||
"screenshot:android": "scripts/screenshot-android.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:json-to-csv": "yarn --cwd scripts/dae json-to-csv",
|
||||||
"dae:csv-to-db": "yarn --cwd scripts/dae csv-to-db",
|
"dae:csv-to-db": "yarn --cwd scripts/dae csv-to-db",
|
||||||
"dae:build": "yarn --cwd scripts/dae build"
|
"dae:build": "yarn --cwd scripts/dae build"
|
||||||
|
|
|
||||||
45
scripts/dae/download-geodae.mjs
Normal file
45
scripts/dae/download-geodae.mjs
Normal file
|
|
@ -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);
|
||||||
|
});
|
||||||
|
|
@ -5,10 +5,11 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"packageManager": "yarn@4.5.3",
|
"packageManager": "yarn@4.5.3",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"download": "node download-geodae.mjs",
|
||||||
"json-to-csv": "node geodae-to-csv.js",
|
"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": "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 ';'",
|
"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": {
|
"dependencies": {
|
||||||
"better-sqlite3": "^11.7.0",
|
"better-sqlite3": "^11.7.0",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue