require 'json' input = File.open(ARGV[0]) do |file| JSON.load(file) end filtered = input.select do |cardJson| cardJson["object"] == "card" && # It needs to have a downloadable image cardJson.count("image_uris") && # Make sure we can support the card layout ["normal", "leveler", "saga"].include?(cardJson["layout"]) && # We only support modern and m15 frames ["2015", "2003"].include?(cardJson["frame"]) && # Digital cards look slightly different so ignore them !cardJson["digital"] && # Only use english printings cardJson["lang"] == "en" && # Currently not supporting silver bordered cards cardJson["border_color"] != "silver" && # It is hard to read the name of a planeswalker !cardJson["type_line"].include?("Planeswalker") && # This cuts out checklists and special tokens cardJson["type_line"] != "Card" && # Amonkhet invocations are impossible cardJson["set"] != "mp2" && # Unknown Event is not a real thing huh cardJson["set"] != "da1" end.map do |cardJson| { "id" => cardJson["id"], "name" => cardJson["name"], "imageUri" => cardJson["image_uris"]["png"], "frame" => cardJson["frame"], "artist" => cardJson["artist"] } end File.open(ARGV[1], 'w') do |file| JSON.dump(filtered, file) end