Last active
August 29, 2015 14:20
-
-
Save walaura/44e7cb3cbcb99ae36904 to your computer and use it in GitHub Desktop.
Get stats (well, msgs posted) from WA chat backups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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