Compare commits

...

2 commits

Author SHA1 Message Date
ec0b8d9cb9 Only prompt for Neologin cookie once when running rails neopets:import 2024-11-16 12:11:13 -08:00
a57b3629db Refactor Neopets import tasks all into a neopets:import namespace
and with a `rails neopets:import` task you can call to do them all at
once!

I'm gonna do some other stuff here too to make `neopets:import` easier
to call all in one go, like prompting for the Neologin cookie just
once at the start.

Note that this changes the cron setup, so you gotta run
`bin/deploy:setup` after this deploys!
2024-11-16 11:58:43 -08:00
5 changed files with 53 additions and 12 deletions

View file

@ -442,13 +442,21 @@
mode: "755"
state: directory
- name: Create 10min cron job to run `rails nc_mall:sync`
- name: Remove 10min cron job to run `rails nc_mall:sync`
become_user: impress
cron:
state: absent
name: "Impress: sync NC Mall data"
minute: "*/10"
job: "bash -c 'source /etc/profile && source ~/.bash_profile && cd /srv/impress/current && bin/rails nc_mall:sync'"
- name: Create 10min cron job to run `rails neopets:import:nc_mall`
become_user: impress
cron:
name: "Impress: import NC Mall data"
minute: "*/10"
job: "bash -c 'source /etc/profile && source ~/.bash_profile && cd /srv/impress/current && bin/rails neopets:import:nc_mall'"
- name: Create weekly cron job to run `rails public_data:commit`
become_user: impress
cron:

View file

@ -0,0 +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

View file

@ -1,9 +1,11 @@
namespace :nc_mall do
namespace "neopets:import" do
desc "Sync our NCMallRecord table with the live NC Mall"
task :sync => :environment do
task :nc_mall => :environment do
# Log to STDOUT.
Rails.logger = Logger.new(STDOUT)
puts "Importing from NC Mall…"
# First, load all records of what's being sold in the live NC Mall. We load
# the homepage and all pages linked from the main document, and extract the
# items from each. (We also de-duplicate the items, which is important

View file

@ -1,10 +1,10 @@
require "addressable/template"
require "async/http/internet/instance"
namespace :rainbow_pool do
namespace "neopets:import" do
desc "Import all basic image hashes from the Rainbow Pool, onto PetTypes"
task :import => :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
all_pet_types_by_species_id_and_color_id = all_pet_types.
@ -16,7 +16,7 @@ namespace :rainbow_pool 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

View file

@ -1,7 +1,7 @@
namespace :alt_styles do
desc "Import alt style info from the NC Mall"
task :import => :environment do
neologin = STDIN.getpass("Neologin cookie: ")
namespace "neopets:import" do
desc "Import alt style info from the NC Styling Studio"
task :styling_studio => ["neopets:import:neologin", :environment] do
puts "Importing from Styling Studio…"
all_species = Species.order(:name).to_a
@ -19,7 +19,7 @@ namespace :alt_styles 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}"