|
@@ -0,0 +1,67 @@
|
|
|
+// node --require regenerator-runtime/runtime --require ./babel-local search.js ..\out result.csv
|
|
|
+
|
|
|
+import {promises} from 'fs';
|
|
|
+import {resolve} from 'path';
|
|
|
+import {eachFormElement, eachItem, eachVestnik} from './lib/read';
|
|
|
+
|
|
|
+const {writeFile, truncate} = promises;
|
|
|
+
|
|
|
+async function work (prefix, outfile) {
|
|
|
+ console.info(`Input directory: ${prefix}`);
|
|
|
+ await truncate(outfile);
|
|
|
+ console.info(`Output file: ${outfile}`);
|
|
|
+ for await (let vestnik of eachVestnik(prefix)) {
|
|
|
+ for (let item of eachItem(vestnik)) {
|
|
|
+ const zakazka = item.zakazka[0].$;
|
|
|
+ const id = zakazka.id || '';
|
|
|
+ const url = zakazka.url || "about:blank";
|
|
|
+ if (hasCpv("45", item)) {
|
|
|
+ const v = oddiel_V(item);
|
|
|
+ if (v) {
|
|
|
+ const pocetPonuk = -1;
|
|
|
+ const predpokladanaCena = '?';
|
|
|
+ const konecnaCena = '?';
|
|
|
+ const vitazIco = 0;
|
|
|
+ const out = async () => await writeFile(
|
|
|
+ outfile,
|
|
|
+ poorMansCsv([id, url, pocetPonuk, predpokladanaCena, konecnaCena, vitazIco]) + "\r\n",
|
|
|
+ {flag: "a"}
|
|
|
+ );
|
|
|
+
|
|
|
+ out();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+function poorMansCsv (items) {
|
|
|
+ return JSON.stringify(items).slice(1, -1);
|
|
|
+}
|
|
|
+
|
|
|
+function hasCpv (prefix, item) {
|
|
|
+ for (let {tag, value, cancel} of eachFormElement(item)) {
|
|
|
+ if (tag === "Part") {
|
|
|
+ const match = value.$.Title && value.$.Title.match(/^ODDIEL\s+(\w+):/);
|
|
|
+ if (match && match[1] !== "II") cancel();
|
|
|
+ }
|
|
|
+ if (tag === "Cpv" && value.$.Code.startsWith(prefix)) return true;
|
|
|
+ if (tag === "SelectList" && value.$.Type === "CPV" && value.SelectListValue && value.SelectListValue[0].$.Title.startsWith(prefix)) return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+function oddiel_V (item) {
|
|
|
+ for (let {tag, value, cancel} of eachFormElement(item)) {
|
|
|
+ if (tag === "Part") {
|
|
|
+ const match = value.$.Title && value.$.Title.match(/^ODDIEL\s+(\w+):/);
|
|
|
+ if (match)
|
|
|
+ if (match[1] === "V") return value; else cancel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return null;
|
|
|
+}
|
|
|
+
|
|
|
+work(resolve(process.argv[2] || ''), resolve(process.argv[3] || 'result.csv'))
|
|
|
+ .catch(error => console.error(error));
|