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..]
|
|
|
|
|
|
|
|
|
|
# Look up the PetType to get its image hash
|
|
|
|
|
pet_type = PetType.matching_name(color_name, species_name).first!
|
|
|
|
|
pet_sci = pet_type.image_hash
|
|
|
|
|
|
|
|
|
|
# Fetch the new image hash for this pet+items combination
|
|
|
|
|
response = Neopets::NCMall.fetch_pet_data(pet_sci, item_ids)
|
|
|
|
|
new_sci = response[:newsci]
|
|
|
|
|
|
|
|
|
|
# Output the hash to stderr for debugging
|
|
|
|
|
$stderr.puts "Generated image hash: #{new_sci}"
|
|
|
|
|
|
|
|
|
|
# Load the full viewer data using the new image hash
|
|
|
|
|
viewer_data = Neopets::CustomPets.fetch_viewer_data("@#{new_sci}")
|
|
|
|
|
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
|