require 'open-uri'
require 'json'
require 'pathname'
# https://api.slack.com/apps
# |> Create New App
# |> Add features and functionality
# |> Permissions
# |> Scopes
# |> emoji:read
# |> xoxp-****
# |> replace TOKEN
TOKEN = 'とーくん'
URL = "https://slack.com/api/emoji.list?token=#{TOKEN}"
IMAGES_DIR = Pathname('images')
IMAGES_DIR.mkpath
body = open(URL, &:read)
emojis = JSON.parse(body)['emoji']
f = ->(_, url) { url.start_with?('alias') }
size = emojis.reject(&f).size
emojis.reject(&f).each.with_index(1) do |(key, url), i|
#puts "#{key} => #{url}"
extention = url.split('.').last
filepath = IMAGES_DIR + "#{key}.#{extention}"
filepath.binwrite open(url, &:read)
print "%3d %%\e[G" % (i*100/size)
end