-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.js
36 lines (30 loc) · 835 Bytes
/
init.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
const line = require('line-by-line')
const fs = require('fs')
function readFileCSVAndParseToJSON() {
let lr = new line('./data/Instagram visits clustering.csv',{
encoding: 'utf8',
start: 0
})
lr.on('error', function (err) {
console.log(err)
});
let result = []
lr.on('line', function(line) {
let string = line
let split = string.split(",")
let obj = {}
let userID = split[0]
let visitScore = split[1]
let spendingRank = split[2]
obj = {
userID,
visitScore,
spendingRank
}
result.push(obj)
})
lr.on('end', function () {
fs.writeFileSync('./data/finalUser.json', JSON.stringify(result), {flag: 'w'})
});
}
readFileCSVAndParseToJSON()