-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse-callback.js
More file actions
54 lines (40 loc) · 1.58 KB
/
parse-callback.js
File metadata and controls
54 lines (40 loc) · 1.58 KB
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
'use strict';
const debug = require('debug')('hello');
const fs = require('fs');
const parse = require('csv-parse');
const helper = require('./helper');
// 0. Naïve
function naive() {
fs.readFile(__dirname + '/sample.csv', function thenParse(err, loadedCsv) {
parse(loadedCsv, function transformEachLine(err, parsed) {
for (let index in parsed) {
let line = parsed[index];
// FIXME: Put your transformation here
let full_name = parsed[index][0]+' '+parsed[index][1]; //format data into full name
if (index > 0) {
debug(`sending data index: ${index - 1}`);
helper.sendSms(full_name, function afterSending(err, sendingStatus) {
let lineToLog;
if (err) {
debug(err.message);
lineToLog = {
sendingStatus,
full_name, //change to full_name
};
}
if (lineToLog) {
helper.logToS3(lineToLog, function afterLogging(err, loggingStatus) {
if (err) {
debug(err.message);
}
// console.log(loggingStatus);
});
}
});
}
index++;
}
});
});
}
naive();