Created
July 26, 2018 18:27
-
-
Save krrishd/5c14c345f070df891696c3dce89f616a to your computer and use it in GitHub Desktop.
get nice data from a slack archive
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
'use strict'; | |
const fs = require('fs'); | |
const path = require('path'); | |
const async = require('async'); | |
const getUserFromMessage = (messageObject, userList) => { | |
const relevantUser = userList.filter(user => { | |
return (user.id == messageObject.user); | |
})[0]; | |
return { | |
name: relevantUser.name, | |
img: relevantUser.profile.image_512 | |
}; | |
} | |
module.exports = (folderPath, callback) => { | |
const users = require(folderPath + '/users.json'); | |
const channels = require(folderPath + '/channels.json'); | |
const channelNames = channels.map(channel => { | |
return `${folderPath}/${channel.name}`; | |
}); | |
const totalChannelContents = []; | |
const traverseChannel = (channelPath, next) => { | |
let channelContents = []; | |
fs.readdir(channelPath, (err, files) => { | |
if (err) { | |
throw(err); | |
} | |
files.map(file => { | |
return path.join(channelPath, file); | |
}).filter(file => { | |
return fs.statSync(file).isFile() | |
}).forEach(file => { | |
const contents = require(`./${file}`); | |
contents.forEach(message => { | |
totalChannelContents.push(message); | |
}); | |
}); | |
next(); | |
}); | |
}; | |
async.each(channelNames, traverseChannel, err => { | |
callback({ | |
totalChannelContents, | |
getUserFromMessage, | |
users | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment