Created
November 5, 2018 08:04
-
-
Save swordfeng/b67b2105d07ded991a7f5a9e99598fac to your computer and use it in GitHub Desktop.
Count number of messages for each person
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
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