You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

const fs = require("fs");
const path = require("path");
const raw = fs.readFileSync(path.join(__dirname, "./emode.dump"), 'utf8').replace(/\r\n/g, '\n');
const escapes = [
"32, Tolbooth Street",
"303, 33rd Street",
"33, Magnolia Street",
"44, 5th Avenue",
"32, Sundance Place",
"8260, Ocean Lane",
"5, Newbury Avenue",
"Belts,bags,wallets",
"Hats,gloves,scarves",
"Belts, bags, wallets",
"Hats, gloves, scarves",
];
const split = raw.split("SQL>");
for (const db of split) {
let [firstLine, ...rest] = db.split("\n");
const data = /^\s*select \* from ([A-Z_]+);$/.exec(firstLine);
rest = rest.filter((line) => !!line.trim() && !line.match(/^\d+ rows selected\.$/));
rest = rest.map((line) => {
for (const escape of escapes) {
line = line.replace(new RegExp(escape + "\\s*", "g"), `"${escape}"`);
}
return line.replace(/\s*(?=,|$)/g, '');
});
if (data) {
fs.writeFileSync(path.join(__dirname, `${data[1].toLowerCase()}.csv`), rest.join('\n'));
}
}