Skip to content

Instantly share code, notes, and snippets.

@reanimus
Created December 23, 2019 10:15
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 reanimus/cf95f794bfd7832b3b36e891e5f89d31 to your computer and use it in GitHub Desktop.
Save reanimus/cf95f794bfd7832b3b36e891e5f89d31 to your computer and use it in GitHub Desktop.
Quick ruby snippet to assign categories to mutant standard emoji in Mastodon
require 'json'
path = ARGV.shift
if path === nil then
puts "path to data.json required"
exit
end
categories_map = {
"activities_clothing" => "Activity",
"expressions" => "People",
"food_drink_herbs" => "Food & Drink",
"gsr" => "LGBTQ",
"nature" => "Nature",
"objects" => "Objects",
"people" => "People",
"symbols" => "Symbols",
"travel_places" => "Travel & Places",
"utils" => "Utilities"
}
File.open(path) do |file|
info = JSON.parse(file.read)
info.each do |emoji|
cat = CustomEmojiCategory.find_or_create_by(name: categories_map[emoji["cat"]])
shortcode = "ms_" + emoji["short"]
dbe = CustomEmoji.find_by(domain: nil, shortcode: shortcode)
if dbe === nil then
puts "Emoji :" + shortcode + ": ( " + emoji["desc"] + ") not found."
next
end
dbe.category = cat
if not dbe.save
puts "Failed to update :" + shortcode +":"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment