-
Notifications
You must be signed in to change notification settings - Fork 2
/
convert.js
50 lines (42 loc) · 1.02 KB
/
convert.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
/**
* Converter
*/
var filepath = 'data-xperium';
var fs = require('fs');
fs.readdir(filepath, function(err, files) {
var users = {};
files.forEach(function(filename) {
if (filename.split('.').pop() != 'json') {
return;
}
var content = fs.readFileSync(filepath + '/' + filename, {encoding: 'utf-8'});
JSON.parse(content).forEach(function(value) {
var userId = value['header']['userId'];
if(!(userId in users)) {
users[userId] = [];
}
users[userId].push({
header: {
scriptVersion: value['header']['scriptVersion'],
date: filename.substring(0, 10)
},
data: value['data']
});
});
});
// Write user files
fs.mkdir(filepath + '/convert/', function(err) {
if(err) {
// directory already exists
}
for(user in users) {
var data = JSON.stringify(users[user], null, 2);
fs.writeFile(filepath + '/convert/' + user + '.json', data, function(err) {
if(err) {
console.log('error writing');
}
});
}
});
console.log('All data are loaded!');
});