Skip to content

Instantly share code, notes, and snippets.

@dperussina
Created August 12, 2019 19:25
Show Gist options
  • Save dperussina/a83a2c5a3319275be059a02b2f7adbf0 to your computer and use it in GitHub Desktop.
Save dperussina/a83a2c5a3319275be059a02b2f7adbf0 to your computer and use it in GitHub Desktop.
function parseFile(callback) {
U.logLn('parseFile - Number of files to process', FILES.length);
if (FILES.length == 0) {
callback(false);
return;
}
DATA = [];
function parse(file) {
var csvFilePath = '/home/dperussina/apps/customer-api-connections/src/dania/queue/' + file;
return function (cb) {
try {
CSV()
.fromFile(csvFilePath)
.on('json', (jsonObj) => {
DATA.push(jsonObj);
})
.on('done', (error) => {
if (error) {
ERRORS.push({
source: 'parseFile',
stack: error
});
cb(true, 'CSV error' + error);
return;
}
cb(false);
});
} catch (err) {
ERRORS.push({
stack: err,
file: csvFilePath
});
cb(true);
}
}
}
Q(FILES, parse, function (err, reply) {
callback(err);
});
}
function main() {
ASYNC.series([getFile, parseFile, mapFields, exec, cleanUp], done);
}
function parseFile(callback) {
U.logLn('parseFile - Number of files to process', FILES.length);
if (FILES.length == 0) {
callback(false);
return;
}
DATA = [];
function parse(file) {
//var csvFilePath = '/home/dperussina/apps/customer-api-connections/src/dania/queue/' + file;
var csvFilePath = './<DirectoryOfChoice>/' + file;
return function (cb) {
try {
CSV()
.fromFile(csvFilePath)
.on('json', (jsonObj) => {
DATA.push(jsonObj);
})
.on('done', (error) => {
if (error) {
ERRORS.push({
source: 'parseFile',
stack: error
});
cb(true, 'CSV error' + error);
return;
}
cb(false);
});
} catch (err) {
ERRORS.push({
stack: err,
file: csvFilePath
});
cb(true);
}
}
}
Q(FILES, parse, function (err, reply) {
callback(err);
});
}
function main() {
//ASYNC.series([getFile, parseFile, mapFields, exec, cleanUp], done);
ASYNC.series([parseFile, mapFields, exec, cleanUp], done);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment