Skip to content

Instantly share code, notes, and snippets.

@walaura
Last active August 29, 2015 14:20
Show Gist options
  • Save walaura/44e7cb3cbcb99ae36904 to your computer and use it in GitHub Desktop.
Save walaura/44e7cb3cbcb99ae36904 to your computer and use it in GitHub Desktop.
Get stats (well, msgs posted) from WA chat backups
var fs = require('fs');
var file = fs.readFileSync('chat.txt');
var lines = file.toString().split("\n");
var users = {};
lines.map(function(line){
var userArr = line.match(/-\ (.*?)\:/);
if(userArr === null || typeof userArr !== 'object') {
return;
}
var user = userArr[1];
if(!users[user]){
users[user] = 0;
}
users[user]++;
})
var csv = '';
for(var i in users) {
csv += i+','+users[i]+"\n";
}
console.log(csv);
fs.writeFileSync('data.csv', csv, 'utf-8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment