Skip to content

Instantly share code, notes, and snippets.

@jmkoni
Last active April 9, 2020 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmkoni/34c9ff9d8ca92cb2de5c5d88d4a7d01a to your computer and use it in GitHub Desktop.
Save jmkoni/34c9ff9d8ca92cb2de5c5d88d4a7d01a to your computer and use it in GitHub Desktop.
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