Skip to content

Instantly share code, notes, and snippets.

@stpe
Created March 10, 2016 09:54
Show Gist options
  • Save stpe/d5b262a11c99bf4ec280 to your computer and use it in GitHub Desktop.
Save stpe/d5b262a11c99bf4ec280 to your computer and use it in GitHub Desktop.
Parse Slack export to show top list of most popular emojis
"use strict";
var fs = require("fs");
var path = require("path");
var dir = "./export";
let count = fs.readdirSync(dir)
// we only want channel sub-directories
.filter(file => fs.statSync(path.join(dir, file)).isDirectory())
.reduce((a, subdir) => a.concat(
// read sub-directory
fs.readdirSync(path.join(dir, subdir))
// parse each logfile
.map(file => JSON.parse(fs.readFileSync(path.join(dir, subdir, file))))
), [])
// flatten array of array of messages
.reduce((a, b) => a.concat(b), [])
// keep only messages with text property and not bots!
.filter(msg => msg.user && msg.type == "message" && !msg.subtype)
// count occurences for each emoji
.reduce((count, msg) => {
(msg.text.match(/:([a-z0-9_]+):/g) || [])
.forEach(emoji => count[emoji] ? count[emoji]++ : count[emoji] = 1);
return count;
}, {});
// print top list
Object
.keys(count)
.sort((a, b) => count[b] - count[a])
.forEach(emoji => console.log(`${emoji} ${count[emoji]}`));
@isabellamnav
Copy link

Awesome! Thank you for the welcome and for responding :)

Turns out our archives are in JSON format so this will work for us!

Thanks again for sharing your knowledge!

@boatiemcboatface
Copy link

Wow, This worked really well, Thank you for sharing this!

Question though, as I too am new to github and coding in general. Do you know how I can make it so that it doesn't grab the emojis in user's slack statuses? We use an app that automatically sets everyone's status to an emoji based on what their calendar status currently is and I think the report that I received was mostly just those emojis from statuses given that they were the calendar emoji and the bulb emoji which almost noone would use except for that app. Any ideas? Thanks again for creating this though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment