|
@@ -1,10 +1,12 @@
|
|
|
-// node --require regenerator-runtime/runtime --require ./babel-local --require isomorphic-fetch index.js
|
|
|
+// node --require regenerator-runtime/runtime --require ./babel-local --require isomorphic-fetch index.js ..\out
|
|
|
|
|
|
import {createWriteStream, promises} from 'fs';
|
|
|
+import {resolve} from 'path';
|
|
|
|
|
|
const {access, rename} = promises;
|
|
|
|
|
|
-async function work () {
|
|
|
+async function work (prefix) {
|
|
|
+ console.info(`Output directory: ${prefix}`);
|
|
|
let rootUri = 'https://data.gov.sk/api/3/action/package_search?fq=%2btitle:Vestn%C3%ADk%20verejn%C3%A9ho%20obstar%C3%A1vania*&rows=9999&sort=metadata_created_date%20asc';
|
|
|
const datasetsRaw = await fetch(rootUri);
|
|
|
const {result: {count, results}} = await datasetsRaw.json();
|
|
@@ -14,13 +16,13 @@ async function work () {
|
|
|
const saves = [];
|
|
|
for (let {name, description, url} of resources) {
|
|
|
const [, issue, year] = name.match(/(\d+)\/(\d+)/);
|
|
|
- const target = `${year}.${issue}.xml`;
|
|
|
+ const target = `${prefix}/${year}.${issue}.xml`;
|
|
|
if (await access(target).then(() => true, () => false))
|
|
|
continue;
|
|
|
console.info(`File ${year} / ${issue}: ${description}`);
|
|
|
const xmlRaw = await fetch(url);
|
|
|
saves.push((async () => {
|
|
|
- const temporary = `${year}.${issue}.xml.download`;
|
|
|
+ const temporary = `${prefix}/${year}.${issue}.xml.download`;
|
|
|
await xmlRaw.body.pipe(createWriteStream(temporary));
|
|
|
await rename(temporary, target);
|
|
|
})());
|
|
@@ -30,4 +32,5 @@ async function work () {
|
|
|
return results;
|
|
|
}
|
|
|
|
|
|
-work().catch(error => console.error(error));
|
|
|
+work(resolve(process.argv[2] || ''))
|
|
|
+ .catch(error => console.error(error));
|