diff --git a/app/lib/vk.rb b/app/lib/vk.rb index 4857f17..0666cdb 100644 --- a/app/lib/vk.rb +++ b/app/lib/vk.rb @@ -63,12 +63,15 @@ def self.retry_handle_429(response, desired_uri) queries['key'] = digest x.query = queries.to_query - last_response = Net::HTTP.get_response(x) + challenge_response = Net::HTTP.get_response(x) - raise 'Vk 429 not success' if last_response['x-challenge'] != 'success' - s429 = CGI.parse(URI.join(vk, last_response['location']).query)['s429'].first + raise 'Vk 429 not success' if challenge_response['x-challenge'] != 'success' + cookies = challenge_response['set-cookie'] + location = URI.join(vk, challenge_response['location']) - URI("#{desired_uri}&s429=#{s429}") + redirected = Net::HTTP.get_response(location, { 'Cookie' => cookies }) + + URI.join(vk, redirected['location']) end def self.parse_salt(s) @@ -129,6 +132,8 @@ def self.js_func(s, arg = nil) end end return nil + else + raise "Unknown function #{s}" end end diff --git a/lib/tasks/parse.rake b/lib/tasks/parse.rake index 66b096b..f7f3346 100644 --- a/lib/tasks/parse.rake +++ b/lib/tasks/parse.rake @@ -6,6 +6,11 @@ namespace :parse do ParseBoardWorker.perform_async(135725718, 34975471) end + desc "Parse packages from https://vk.com/topic-228528109_53000017" + task vk_si_2: :environment do + ParseBoardWorker.perform_async(228528109, 53000017) + end + desc "Parse one post by post id synchronously" task :vk_si_game_one, [:id] => :environment do |t, args| ParseBoardWorker.new.parse_one_post(135725718, 34975471, args[:id])