From 464bc84394c0fc8f955edf9ed052867b7e47d1d9 Mon Sep 17 00:00:00 2001 From: Ilgiz Mustafin Date: Wed, 4 Dec 2024 23:11:28 +0100 Subject: [PATCH] Update parsing --- app/lib/vk.rb | 13 +++++++++---- lib/tasks/parse.rake | 5 +++++ 2 files changed, 14 insertions(+), 4 deletions(-) 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])