Skip to content

Instantly share code, notes, and snippets.

@swordfeng
Created November 5, 2018 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swordfeng/b67b2105d07ded991a7f5a9e99598fac to your computer and use it in GitHub Desktop.
Save swordfeng/b67b2105d07ded991a7f5a9e99598fac to your computer and use it in GitHub Desktop.
Count number of messages for each person
const fs = require('fs');
const cheerio = require('cheerio');
require('console.table');
const count = {};
for (let f of fs.readdirSync('.')) {
if (f.endsWith('.html')) {
let content = fs.readFileSync(f);
countContent(content);
}
}
function countContent(content) {
const $ = cheerio.load(content);
const names = $('.message.default > .body > div.from_name');
//console.log(names.length);
for (let i = 0; i < names.length; i++) {
let name = names[i].children[0].data.trim();
if (!(name in count)) {
count[name] = 0;
}
count[name]++;
}
}
const res = [];
for (let name in count) {
res.push({name, count: count[name]});
}
res.sort((a, b) => b.count - a.count);
console.table(res);
console.log('Total # of Names:', res.length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment