Created
March 10, 2016 09:54
-
-
Save stpe/d5b262a11c99bf4ec280 to your computer and use it in GitHub Desktop.
Parse Slack export to show top list of most popular emojis
This file contains hidden or 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
"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]}`)); |
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!
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
Hi @isabellamnav! Welcome to Github!
This code uses the directory as specified with
dir
to look for sub-directories of each channel, and then parse the channel log file (as it was structured 5 years ago, at least), which is in JSON format.It cannot be used without modification to use a csv file. Parts of the code may probably be re-used if the csv file is parsed into a similar structure as the JSON file.