-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
67 lines (54 loc) · 1.26 KB
/
index.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
var lineReader = require('readline').createInterface({
input: require('fs').createReadStream('terc.csv')
});
var _ = require('lodash');
var fs = require('fs');
var db = {};
lineReader.on('line', function (line) {
var tokens = line.split(';');
var a = { };
a[tokens[0]] = { };
var lvl = a[tokens[0]];
var step = 0;
if (!_.isEmpty(tokens[1])) {
lvl[tokens[1]] = { };
lvl = lvl[tokens[1]];
step = 1;
if (!_.isEmpty(tokens[2])) {
lvl[tokens[2]] = { };
lvl = lvl[tokens[2]];
step = 2;
}
}
lvl.name = tokens[4];
db = _.merge(db, a);
});
var lineReader2 = require('readline').createInterface({
input: require('fs').createReadStream('simc.csv')
});
lineReader2.on('line', function (line) {
var tokens = line.split(';');
var lvl = db[tokens[0]];
var step = 0;
if (!_.isEmpty(lvl[tokens[1]])) {
lvl = lvl[tokens[1]];
step = 1;
if (!_.isEmpty(lvl[tokens[2]])) {
lvl = lvl[tokens[2]];
step = 2;
}
}
if (step == 2) {
lvl[tokens[7]] = {
name: tokens[6],
};
}
});
lineReader2.on('close', function () {
fs.writeFile("pl.json", JSON.stringify(db, 0, 2), function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});
})