Created
December 23, 2019 10:15
-
-
Save reanimus/cf95f794bfd7832b3b36e891e5f89d31 to your computer and use it in GitHub Desktop.
Quick ruby snippet to assign categories to mutant standard emoji in Mastodon
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' | |
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