diff --git a/Gemfile b/Gemfile index 596ebb42..d09e78a8 100644 --- a/Gemfile +++ b/Gemfile @@ -57,6 +57,8 @@ gem "globalize3" gem "flex", :require => "flex/rails", :git => "git@github.com:matchu/flex.git" gem "patron", "~> 0.4.18" +gem "rest-client", "~> 1.6.7" + group :development do gem "bullet", "~> 4.1.5" end diff --git a/Gemfile.lock b/Gemfile.lock index 600f57e0..de8c02a3 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -220,6 +220,8 @@ GEM redis (>= 2.0.1) resque (>= 1.15.0) rufus-scheduler + rest-client (1.6.7) + mime-types (>= 1.16) right_aws (2.1.0) right_http_connection (>= 1.2.5) right_http_connection (1.3.0) @@ -304,6 +306,7 @@ DEPENDENCIES resque (~> 1.15.0) resque-retry (~> 0.1.0) resque-scheduler (~> 2.0.0.d) + rest-client (~> 1.6.7) right_aws (~> 2.1.0) rspec-rails (~> 2.0.0.beta.22) sanitize (~> 2.0.3) diff --git a/lib/tasks/translate.rake b/lib/tasks/translate.rake index b73823cc..a9965db0 100644 --- a/lib/tasks/translate.rake +++ b/lib/tasks/translate.rake @@ -1,17 +1,6 @@ require 'rocketamf/remote_gateway' namespace :translate do - def with_given_locale - I18n.with_locale(ENV['LOCALE']) do - language_code = I18n.neopets_language_code_for(I18n.locale) - unless language_code - raise "Locale #{I18n.locale.inspect} has no neopets language code" - end - - yield(language_code) - end - end - desc "Download the Neopets zone data for the given locale" task :zones => :environment do with_given_locale do |neopets_language_code| @@ -24,7 +13,7 @@ namespace :translate do ) application_data = envelope.messages[0].data.body - zones_by_id = Zone.all.inject({}) { |h, z| h[z.id] = z ; h} + zones_by_id = Zone.all.inject({}) { |h, z| h[z.id] = z ; h } application_data[:zones].each do |zone_data| zone = zones_by_id[zone_data[:id].to_i] zone.label = zone_data[:label] @@ -33,4 +22,38 @@ namespace :translate do end end end + + desc "Download the Rainbow Pool data for the given locale" + task :pet_attributes => :environment do + with_given_locale do |neopets_language_code| + pool_url = "http://www.neopets.com/pool/all_pb.phtml" + pool_options = { + :cookies => {:neologin => URI.encode(ENV['NEOLOGIN'])}, + :params => {:lang => neopets_language_code} + } + pool_response = RestClient.get(pool_url, pool_options) + pool_doc = Nokogiri::HTML(pool_response) + + [Species, Color].each do |klass| + klass_name = klass.name.underscore + records_by_id = klass.all.inject({}) { |h, r| h[r.id] = r; h } + pool_doc.css("select[name=f_#{klass_name}_id] option").each do |option| + record = records_by_id[option['value'].to_i] + record.name = option.text.downcase + record.save! + end + end + end + end + + def with_given_locale + I18n.with_locale(ENV['LOCALE']) do + language_code = I18n.neopets_language_code_for(I18n.locale) + unless language_code + raise "Locale #{I18n.locale.inspect} has no neopets language code" + end + + yield(language_code) + end + end end diff --git a/vendor/cache/rest-client-1.6.7.gem b/vendor/cache/rest-client-1.6.7.gem new file mode 100644 index 00000000..0cba1056 Binary files /dev/null and b/vendor/cache/rest-client-1.6.7.gem differ