forked from oster/rtce-experiments-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pretty-chat.js
executable file
·48 lines (35 loc) · 971 Bytes
/
pretty-chat.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
#!/opt/local/bin/node
/**
* This script pretty-prints a chat record from etherpad-lite.
* The record must have been retrieved via etherpad-lite API (getChat).
*/
var fs = require('fs');
if (process.argv.length != 3) {
console.log("usage: pretty-chat.js chat-record.json");
process.exit(1);
}
var jsonFileName = process.argv[2];
var users = new Object();
var usersCount = 0;
fs.readFile(jsonFileName, 'utf8', function (err, data) {
if (err) throw err;
var chat = JSON.parse(data);
chat.data.forEach(function(item) {
var username = item.userName;
var userid = item.userId;
var time = new Date(item.time).toLocaleTimeString();
var msg = item.text;
if (username == null) {
username = generateSequentialUserName(userid);
}
console.log("["+time+"] "+username+":> "+msg);
});
});
function generateSequentialUserName(uid) {
var res = users[uid];
if (! res) {
res = "User"+(++usersCount);
users[uid] = res;
}
return res;
};