Skip to content

Instantly share code, notes, and snippets.

@tanookiben
Created November 9, 2017 00:32
Show Gist options
  • Save tanookiben/a27ae143b763645bde4173523c35be35 to your computer and use it in GitHub Desktop.
Save tanookiben/a27ae143b763645bde4173523c35be35 to your computer and use it in GitHub Desktop.
Slack Emojis
require 'net/http'
require 'json'
token = ENV['SLACK_API_TOKEN']
srcdir = ENV['SOURCE_DIR']
base = 'https://slack.com/api/emoji.list'
url = "#{base}?token=#{token}"
res = Net::HTTP.get(URI(url))
body = JSON.parse(res)
emoji = body['emoji']
emoji.each do |name, src|
src.match(/(\.\w{3}\z)/)
ext = $1
if !ext.nil?
filename = "#{name}#{ext}"
filepath = "#{srcdir}/#{filename}"
if !File.exists?(filepath)
puts "Saving #{filename}"
system("wget --quiet -O \"#{filepath}\" #{src} >/dev/null")
else
puts "Skipping #{filename}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment