2024-01-24 00:51:37 -08:00
|
|
|
namespace :pets do
|
2026-01-04 18:38:01 -08:00
|
|
|
desc "Load a pet's viewer data (by name or by color/species/items)"
|
|
|
|
|
task :load, [:first] => [:environment] do |task, args|
|
|
|
|
|
# Collect all arguments (first + extras)
|
|
|
|
|
all_args = [args[:first]] + args.extras
|
|
|
|
|
|
|
|
|
|
# If only one argument, treat it as a pet name
|
|
|
|
|
if all_args.length == 1
|
|
|
|
|
viewer_data = Neopets::CustomPets.fetch_viewer_data(all_args[0])
|
|
|
|
|
else
|
|
|
|
|
# Multiple arguments: color, species, and optional item IDs
|
|
|
|
|
color_name = all_args[0]
|
|
|
|
|
species_name = all_args[1]
|
|
|
|
|
item_ids = all_args[2..]
|
|
|
|
|
|
2026-01-20 18:23:52 -08:00
|
|
|
# Look up the PetType to use for the preview
|
2026-01-04 18:38:01 -08:00
|
|
|
pet_type = PetType.matching_name(color_name, species_name).first!
|
|
|
|
|
|
2026-01-20 18:23:52 -08:00
|
|
|
# Convert it to an image hash for direct lookup
|
|
|
|
|
new_image_hash = Neopets::NCMall.fetch_pet_data_sci(pet_type.image_hash, item_ids)
|
|
|
|
|
pet_name = '@' + new_image_hash
|
|
|
|
|
$stderr.puts "Loading pet #{pet_name}"
|
2026-01-04 18:38:01 -08:00
|
|
|
|
2026-01-20 18:23:52 -08:00
|
|
|
# Load the image hash as if it were a pet
|
|
|
|
|
viewer_data = Neopets::CustomPets.fetch_viewer_data(pet_name)
|
2026-01-04 18:38:01 -08:00
|
|
|
end
|
|
|
|
|
|
2024-10-21 14:03:56 -07:00
|
|
|
puts JSON.pretty_generate(viewer_data)
|
2024-01-24 00:51:37 -08:00
|
|
|
end
|
2024-09-13 18:59:17 -07:00
|
|
|
|
|
|
|
|
desc "Find pets that were, last we saw, of the given color and species"
|
|
|
|
|
task :find, [:color_name, :species_name] => [:environment] do |task, args|
|
|
|
|
|
begin
|
|
|
|
|
pt = PetType.matching_name(args.color_name, args.species_name).first!
|
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
|
abort "Could not find pet type for " +
|
2024-10-18 17:40:31 -07:00
|
|
|
"#{args.color_name} #{args.species_name}"
|
2024-09-13 18:59:17 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
limit = ENV.fetch("LIMIT", 10)
|
|
|
|
|
|
|
|
|
|
pt.pets.limit(limit).order(id: :desc).pluck(:name).each do |pet_name|
|
|
|
|
|
puts "- #{pet_name} (https://www.neopets.com/petlookup.phtml?pet=#{pet_name})"
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-01-24 00:51:37 -08:00
|
|
|
end
|