Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'json'
require 'open-uri'
Dir.mkdir('emojis') unless Dir.exist?('emojis')
number = Integer(ARGV[0]) || 10
# assuming you have numbered the files correctly, loops through each
(1..number).each do |i|
file = File.open("emoji#{i}.json")
data = JSON.load(file)
# we only care about the data within "emoji" key
data["emoji"].each do | emoji |
begin
url = emoji["url"]
file_type = url.split(".").last
file_name = emoji["name"] + "." + file_type
# if you've done this for multiple slacks, you might have duplicates
if File.file?("emojis/#{file_name}")
puts "skipping #{file_name}, url: #{url}"
next
end
puts "writing #{file_name}"
File.write "emojis/#{file_name}", open(url).read
rescue
puts "Error downloading: #{emoji["url"]}"
next
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.