-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleandata.js
31 lines (27 loc) · 1.11 KB
/
cleandata.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
const fs = require('fs');
const readline = require('readline');
const converter_to_csv = require('json-2-csv');
const DATA_DIR = 'GeneratedData';
const DIR_TO_PUT_CSV = 'GeneratedCSV';
const helper = require('./helper');
// read dir
fs.readdirSync(DATA_DIR).forEach(async (file) => {
if (file.split('.').pop() === 'filtered') {
await helper.processLineByLine(DATA_DIR + '/' + file)
.then(decoded_data => {
// create the new csv file which will contains the decoded GeneratedCSV
converter_to_csv.json2csv(decoded_data, function (err, csv) {
if (err) throw err;
fs.writeFile(DIR_TO_PUT_CSV + '/' + file + '.csv', csv, 'utf8', (err) =>
{
if (err) {
console.log('Some error occured - file either not saved or corrupted file saved.');
} else {
console.log('It\'s saved!');
}
});
});
})
.catch(reason => console.log(reason));
}
});