Sha256: 9048e921c72de4a3afa73b7d6e2ed0871a45250013eed8e69f08b75924b1a016
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true module Cotcube module CftcSource # method to download all available historical cot report files # # @param [Integer, String] year # @param [Boolean] debug # @param [Hash] config def fetch(year: Time.now.year, debug: false, silent: false, config: init) recent_report_date = `tail -n1 #{config[:data_path]}/cot/13874A/legacy_com.csv | cut -d ',' -f 3`.chomp CFTC_LINKS.each do |report, a| a.each do |combined, _b| puts ("====> working on #{report}\t#{combined}") if debug raw_dir = "#{config[:data_path]}/raw" uri = "#{CFTC_LINKS[report][combined][:hist]}#{year}.zip" file_data = nil input = HTTParty.get(uri).body Zip::InputStream.open(StringIO.new(input)) do |io| while entry = io.get_next_entry file_data = io.read end end file = "#{raw_dir}/#{report}_#{combined}_#{year}.csv" File.write(file, file_data) puts "Contents have been written to '#{file}'." if debug current_report_date = `head -n2 #{file} | tail -n1 | cut -d, -f3`.chomp if recent_report_date == current_report_date || current_report_date=='' puts "#{report}:#{combined}\tLast date '#{current_report_date}' is same as recent_date '#{recent_report_date}', please re_run".colorize(:light_yellow) end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cotcube-cftcsource-0.1.2.1 | lib/cotcube-cftcsource/fetch.rb |