SU2-2 | Скрипт интегрирован в sidekiq, создан простой интерфейс на взаимодействие с SK, тест на нескольких ИНН
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
require 'httparty'
|
||||
require 'json'
|
||||
require 'zip'
|
||||
require 'stringio'
|
||||
require 'optparse'
|
||||
|
||||
def get_content(url, json_need = false)
|
||||
headers = {
|
||||
'User-Agent' => "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
||||
'Accept-Language' => 'en-US,en;q=0.9',
|
||||
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
|
||||
}
|
||||
content = HTTParty.get(url, headers: headers).body
|
||||
json_need ? JSON.parse(content) : content
|
||||
end
|
||||
|
||||
def download_INN(inn, output)
|
||||
url = "https://bo.nalog.gov.ru/advanced-search/organizations/search?query=#{inn}&page=0&size=20"
|
||||
content = get_content(url, true)
|
||||
id = content['content'][0]['id']
|
||||
url = "https://bo.nalog.gov.ru/nbo/organizations/#{id}/bfo/"
|
||||
content = get_content(url, true)
|
||||
periods_and_details_ids = content.map { |item| [item['period'], item['typeCorrections'][0]['correction']['id']] }
|
||||
periods_and_details_ids.each do |period, details_id|
|
||||
url = "https://bo.nalog.gov.ru/download/bfo/#{id}?auditReport=false&balance=true"\
|
||||
"&capitalChange=true&clarification=false&targetedFundsUsing=false&detailsId=#{details_id}"\
|
||||
"&financialResult=true&fundsMovement=true&type=XLS&period=#{period}"
|
||||
content = get_content(url)
|
||||
zip_file = Zip::File.open_buffer(StringIO.new(content))
|
||||
zip_file.each do |entry|
|
||||
zip_file.extract(entry, destination_directory: output)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def main
|
||||
options = {}
|
||||
OptionParser.new do |opt|
|
||||
opt.on('--inn INN', 'INN') { |o| options[:INN] = o }
|
||||
opt.on('--output OUTPUT', 'OUTPUT') { |o| options[:output_path] = o }
|
||||
end.parse!
|
||||
download_INN(options[:INN], options[:output_path])
|
||||
end
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user