diff --git a/map-generator/capture-all-maps.js b/map-generator/capture-all-maps.js new file mode 100644 index 0000000..2f6dd37 --- /dev/null +++ b/map-generator/capture-all-maps.js @@ -0,0 +1,52 @@ +const fs = require('fs'); +const { exec } = require('child_process'); + +var widthArgument = process.argv.at(2); +if (!widthArgument) { + console.log("Defaulting to width of 1080") + width = 1080; +} else { + width = parseInt(widthArgument); + if (isNaN(width)) { + console.log("Invalid width provided"); + exit(1); + } +} + +var heightArgument = process.argv.at(3); +if (!heightArgument) { + console.log("Defaulting to height of 720") + height = 720; +} else { + height = parseInt(heightArgument); + if (isNaN(height)) { + console.log("Invalid height provided"); + exit(1); + } +} + +var dataPathArgument = process.argv.at(4); +if (!dataPathArgument) { + console.log("Invalid data path provided"); + exit(1); +} else { + dataPath = dataPathArgument; +} + +function sleep(ms) { + return new Promise((resolve) => { + setTimeout(resolve, ms); + }); + } + +(async () => { + var councils = JSON.parse(fs.readFileSync('../council_names.json', 'utf8')); + + for (const council of councils) { + console.log("Generating map for " + council.slug + "..."); + exec("node ./capture-map.js " + council.slug + " " + width + " " + height + " " + dataPath + "/" + council.slug + "/map.jpg"); + + // Need to slow down requests to avoid overloading the system... + await sleep(1000); + } +})(); \ No newline at end of file diff --git a/map-generator/package-lock.json b/map-generator/package-lock.json index fc9d60f..d21988e 100644 --- a/map-generator/package-lock.json +++ b/map-generator/package-lock.json @@ -5,6 +5,8 @@ "packages": { "": { "dependencies": { + "child_process": "^1.0.2", + "fs": "^0.0.1-security", "polylabel": "^2.0.1", "puppeteer-core": "^23.1.0" } @@ -201,6 +203,11 @@ "node": "*" } }, + "node_modules/child_process": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/child_process/-/child_process-1.0.2.tgz", + "integrity": "sha512-Wmza/JzL0SiWz7kl6MhIKT5ceIlnFPJX+lwUGj7Clhy5MMldsSoJR0+uvRzOS5Kv45Mq7t1PoE8TsOA9bzvb6g==" + }, "node_modules/chromium-bidi": { "version": "0.6.4", "resolved": "https://registry.npmjs.org/chromium-bidi/-/chromium-bidi-0.6.4.tgz", @@ -386,6 +393,11 @@ "pend": "~1.2.0" } }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==" + }, "node_modules/fs-extra": { "version": "11.2.0", "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", diff --git a/map-generator/package.json b/map-generator/package.json index 43b0637..39240ed 100644 --- a/map-generator/package.json +++ b/map-generator/package.json @@ -1,5 +1,7 @@ { "dependencies": { + "child_process": "^1.0.2", + "fs": "^0.0.1-security", "polylabel": "^2.0.1", "puppeteer-core": "^23.1.0" } diff --git a/map-generator/readme.md b/map-generator/readme.md index 894b354..39b5589 100644 --- a/map-generator/readme.md +++ b/map-generator/readme.md @@ -12,4 +12,6 @@ To automatically compile the `src.js` file after every edit, run `webpack-cli -- Changes to `dist/main.js` should be committed so that other users don't need to install node. -The `capture-map.js` script can be used to capture an image of the map. It accepts 4 arguments, the council name, width, height, and output path. For example `node .\capture-map.js brimbank 900 500 ../../spl-data/brimbank/map.jpg` would capture a map of Brimbank City Council and place a file named `map.jpg` in the `../../spl-data/brimbank/` folder. \ No newline at end of file +The `capture-map.js` script can be used to capture an image of the map. It accepts 4 arguments, the council name, width, height, and output path. For example `node .\capture-map.js brimbank 900 500 ../../spl-data/brimbank/map.jpg` would capture a map of Brimbank City Council and place a file named `map.jpg` in the `../../spl-data/brimbank/` folder. + +The `capture-all-maps.js` script can be used to capture an image for each council. It accepts 3 arguments, width, height, and the path to the `spl-data` repo. For example `node .\capture-all-maps.js 900 500 ../../spl-data` would capture a map of each council and put it in the spl-data repo in the appropriate folder. \ No newline at end of file