diff --git a/lib/tasks/neopets/import.rake b/lib/tasks/neopets/import.rake index 6c6ecbbd..e4fd5efd 100644 --- a/lib/tasks/neopets/import.rake +++ b/lib/tasks/neopets/import.rake @@ -1,7 +1,31 @@ +module Neologin + def self.cookie + raise "must run neopets:import:neologin first" if @cookie.nil? + @cookie + end + + def self.cookie? + @cookie.present? + end + + def self.cookie=(new_cookie) + @cookie = new_cookie + end +end + namespace :neopets do task :import => [ + "neopets:import:neologin", "neopets:import:nc_mall", "neopets:import:rainbow_pool", "neopets:import:styling_studio", ] + + namespace :import do + task :neologin do + unless Neologin.cookie? + Neologin.cookie = STDIN.getpass("Neologin cookie: ") + end + end + end end diff --git a/lib/tasks/neopets/import/rainbow_pool.rake b/lib/tasks/neopets/import/rainbow_pool.rake index d0910bc9..e0b16bc6 100644 --- a/lib/tasks/neopets/import/rainbow_pool.rake +++ b/lib/tasks/neopets/import/rainbow_pool.rake @@ -3,9 +3,7 @@ require "async/http/internet/instance" namespace "neopets:import" do desc "Import all basic image hashes from the Rainbow Pool, onto PetTypes" - task :rainbow_pool => :environment do - neologin = STDIN.getpass("Neologin cookie: ") - + task :rainbow_pool => ["neopets:import:neologin", :environment] do puts "Importing from Rainbow Pool…" all_pet_types = PetType.all.to_a @@ -18,7 +16,7 @@ namespace "neopets:import" do Species.order(:name).each do |species| begin hashes_by_color_name = RainbowPool.load_hashes_for_species( - species.id, neologin) + species.id, Neologin.cookie) rescue => error puts "Failed to load #{species.name} page, skipping: #{error.message}" next diff --git a/lib/tasks/neopets/import/styling_studio.rake b/lib/tasks/neopets/import/styling_studio.rake index 37e7f2c5..516f5bf4 100644 --- a/lib/tasks/neopets/import/styling_studio.rake +++ b/lib/tasks/neopets/import/styling_studio.rake @@ -1,8 +1,6 @@ namespace "neopets:import" do desc "Import alt style info from the NC Styling Studio" - task :styling_studio => :environment do - neologin = STDIN.getpass("Neologin cookie: ") - + task :styling_studio => ["neopets:import:neologin", :environment] do puts "Importing from Styling Studio…" all_species = Species.order(:name).to_a @@ -21,7 +19,7 @@ namespace "neopets:import" do begin styles_by_species_id[species.id] = Neopets::NCMall.load_styles( species_id: species.id, - neologin:, + neologin: Neologin.cookie, ) rescue => error puts "\n⚠️ Error loading for #{species.human_name}, skipping: #{error.message}"