Download and Zip your slack emoji
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
# gem install slack-ruby-client rubyzip | |
# run with: ruby dlemoji.rb | |
require 'rubygems' | |
require 'zip' | |
require 'slack-ruby-client' | |
require 'open-uri' | |
token = 'your slack api token' | |
directory = '/<absolute/path/to>/emoji/' # The emoji directory must exist, and be empty. | |
zipfile_name = 'emoji.zip' | |
# Download the image from slack's server and save locally | |
def download_image(url, dest, dir = '') | |
open(url) do |u| | |
File.open(dir + dest, 'wb') { |f| f.write(u.read) } | |
end | |
end | |
Slack.configure do |config| | |
config.token = token | |
end | |
client = Slack::Web::Client.new | |
client.emoji_list.emoji.each do |name, url| | |
next if url.include? 'alias:' # skip aliased emoji | |
download_image(url, name + '.' + url.split('.').last, directory) | |
end | |
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| | |
Dir[File.join(directory, '*')].each do |file| | |
zipfile.add(file.sub(directory, ''), file) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment