-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff_check.js
86 lines (79 loc) · 1.75 KB
/
diff_check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const csv = require("csv-parser");
const fs = require("fs");
const createCsvWriter = require("csv-writer").createObjectCsvWriter;
let oldFile = null;
let newFile = null;
let outputFile = null;
let csvWriter = null;
let path = null;
let old_array = [];
const out = [
{
Email: "Email",
FirstName: "FirstName",
LastName: "LastName",
Headline: "Headline",
},
];
const write = (record) => {
csvWriter
.writeRecords(record) // returns a promise
.then(() => {
//console.log('...Done');
});
};
function read(file, onData, onEnd) {
fs.createReadStream(file).pipe(csv()).on("data", onData).on("end", onEnd);
}
let readNewFile = () => {
read(
newFile,
(data) => {
let email = Object.values(data)[1];
if (old_array.includes(email)) {
// duplicate
} else {
//console.log(email);
let name = Object.values(data)[0].split(",");
let head = Object.values(data)[3] + " at " + Object.values(data)[2];
let row = {
Email: email,
FirstName: name[1],
LastName: name[0],
Headline: head,
};
out.push(row);
}
},
() => {
write(out);
}
);
};
let main = () => {
// Read old file
read(
oldFile,
(data) => {
let email = Object.values(data)[0];
old_array.push(email);
},
() => {
readNewFile();
}
);
};
if (process.argv.length < 4) {
console.log("Please provide input and output file names.");
} else {
const start = Date.now();
oldFile = process.argv[2];
newFile = process.argv[3];
outputFile = process.argv[4];
path = start + "_" + outputFile;
csvWriter = createCsvWriter({
path: path,
header: ["Email", "FirstName", "LastName", "Headline"],
});
main();
}