Merge branch 'gender_mood'
This commit is contained in:
commit
a436362f26
9 changed files with 66 additions and 24 deletions
4
Gemfile
4
Gemfile
|
@ -33,12 +33,14 @@ gem 'right_aws', '~> 2.1.0'
|
|||
|
||||
gem "character-encodings", "~> 0.4.1", :platforms => :ruby_18
|
||||
|
||||
gem "nokogiri", "~> 1.5.0"
|
||||
gem "nokogiri", "~> 1.5.2"
|
||||
|
||||
gem 'sanitize', '~> 2.0.3'
|
||||
|
||||
gem 'newrelic_rpm'
|
||||
|
||||
gem 'neopets', :git => 'git://github.com/matchu/neopets.git'
|
||||
|
||||
group :development_async do
|
||||
# async wrappers
|
||||
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
|
||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -29,6 +29,13 @@ GIT
|
|||
em-synchrony (1.0.0)
|
||||
eventmachine (>= 1.0.0.beta.1)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/matchu/neopets.git
|
||||
revision: d0127de12eae650fd85c56b45bc0b52e64e34ffe
|
||||
specs:
|
||||
neopets (0.0.1)
|
||||
nokogiri (~> 1.5.2)
|
||||
|
||||
GIT
|
||||
remote: git://github.com/oldmoe/mysqlplus.git
|
||||
revision: 3dbaa7c00ff0bb75ad9538cdef176c72de35d231
|
||||
|
@ -118,7 +125,7 @@ GEM
|
|||
msgpack (0.4.6)
|
||||
mysql2 (0.2.6)
|
||||
newrelic_rpm (3.3.3)
|
||||
nokogiri (1.5.0)
|
||||
nokogiri (1.5.2)
|
||||
open4 (1.3.0)
|
||||
openneo-auth-signatory (0.1.0)
|
||||
ruby-hmac
|
||||
|
@ -221,8 +228,9 @@ DEPENDENCIES
|
|||
msgpack (~> 0.4.3)
|
||||
mysql2 (< 0.3)
|
||||
mysqlplus!
|
||||
neopets!
|
||||
newrelic_rpm
|
||||
nokogiri (~> 1.5.0)
|
||||
nokogiri (~> 1.5.2)
|
||||
openneo-auth-signatory (~> 0.1.0)
|
||||
rack-fiber_pool
|
||||
rails (= 3.0.5)
|
||||
|
|
|
@ -12,17 +12,15 @@ class NeopetsUser
|
|||
end
|
||||
|
||||
def load!
|
||||
doc = Nokogiri::HTML(open(url))
|
||||
user = Neopets::User.new(@username)
|
||||
|
||||
unless pets_wrapper = doc.at('#userneopets')
|
||||
raise NotFound, "Could not find user #{username}"
|
||||
end
|
||||
|
||||
pets = pets_wrapper.css('a[href^="/petlookup.phtml"]').map do |link|
|
||||
name = link['href'].split('=').last
|
||||
Pet.find_or_initialize_by_name(name)
|
||||
begin
|
||||
pets = user.pets
|
||||
rescue Neopets::User::Error => e
|
||||
raise NotFound, e.message
|
||||
end
|
||||
|
||||
pets = pets.map { |pet| Pet.find_or_initialize_by_name(pet.name) }
|
||||
items = pets.each(&:load!).map(&:items).flatten
|
||||
item_ids = items.map(&:id)
|
||||
|
||||
|
@ -46,13 +44,6 @@ class NeopetsUser
|
|||
false
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
URL_PREFIX = 'http://www.neopets.com/userlookup.phtml?user='
|
||||
def url
|
||||
URL_PREFIX + @username
|
||||
end
|
||||
|
||||
class NotFound < RuntimeError;end
|
||||
class NotFound < RuntimeError; end
|
||||
end
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ class Pet < ActiveRecord::Base
|
|||
biology = pet_data.biology_by_zone
|
||||
biology[0] = nil # remove effects if present
|
||||
@pet_state = self.pet_type.add_pet_state_from_biology! biology
|
||||
@pet_state.label_by_pet(self, pet_data.owner)
|
||||
@items = Item.collection_from_pet_type_and_registries(self.pet_type,
|
||||
contents.object_info_registry, contents.object_asset_registry)
|
||||
true
|
||||
|
|
|
@ -62,6 +62,26 @@ class PetState < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def label_by_pet(pet, username)
|
||||
# If this pet is already labeled with a gender/mood, or it's unconverted
|
||||
# and therefore has none, skip.
|
||||
return false if self.labeled? || self.unconverted?
|
||||
|
||||
# Find this pet on the owner's userlookup, where we can get both its gender
|
||||
# and its mood.
|
||||
user_pet = Neopets::User.new(username).pets.
|
||||
find { |user_pet| user_pet.name.downcase == pet.name.downcase }
|
||||
self.female = user_pet.female?
|
||||
self.mood_id = user_pet.mood.id
|
||||
self.labeled = true
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
def mood
|
||||
Neopets::Pet::Mood.find(self.mood_id)
|
||||
end
|
||||
|
||||
def self.from_pet_type_and_biology_info(pet_type, info)
|
||||
swf_asset_ids = []
|
||||
info.each do |zone_id, asset_info|
|
||||
|
@ -112,6 +132,7 @@ class PetState < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
pet_state.parent_swf_asset_relationships_to_update = relationships
|
||||
pet_state.unconverted = (relationships.size == 1)
|
||||
pet_state
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class AddFemaleAndMoodAndUnconvertedAndLabeledToPetStates < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :pet_states, :female, :boolean
|
||||
add_column :pet_states, :mood_id, :integer
|
||||
add_column :pet_states, :unconverted, :boolean
|
||||
add_column :pet_states, :labeled, :boolean, :null => false, :default => false
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :pet_states, :labeled
|
||||
remove_column :pet_states, :unconverted
|
||||
remove_column :pet_states, :mood_id
|
||||
remove_column :pet_states, :female
|
||||
end
|
||||
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20120321231507) do
|
||||
ActiveRecord::Schema.define(:version => 20120521164652) do
|
||||
|
||||
create_table "auth_servers", :force => true do |t|
|
||||
t.string "short_name", :limit => 10, :null => false
|
||||
|
@ -140,8 +140,12 @@ ActiveRecord::Schema.define(:version => 20120321231507) do
|
|||
end
|
||||
|
||||
create_table "pet_states", :force => true do |t|
|
||||
t.integer "pet_type_id", :limit => 3, :null => false
|
||||
t.text "swf_asset_ids", :null => false
|
||||
t.integer "pet_type_id", :limit => 3, :null => false
|
||||
t.text "swf_asset_ids", :null => false
|
||||
t.boolean "female"
|
||||
t.integer "mood_id"
|
||||
t.boolean "unconverted"
|
||||
t.boolean "labeled", :default => false, :null => false
|
||||
end
|
||||
|
||||
add_index "pet_states", ["pet_type_id"], :name => "pet_states_pet_type_id"
|
||||
|
|
BIN
vendor/cache/nokogiri-1.5.0.gem
vendored
BIN
vendor/cache/nokogiri-1.5.0.gem
vendored
Binary file not shown.
BIN
vendor/cache/nokogiri-1.5.2.gem
vendored
Normal file
BIN
vendor/cache/nokogiri-1.5.2.gem
vendored
Normal file
Binary file not shown.
Loading…
Reference in a new issue