Last active
April 9, 2020 19:44
-
-
Save jmkoni/34c9ff9d8ca92cb2de5c5d88d4a7d01a to your computer and use it in GitHub Desktop.
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
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