Class | OfacSdnLoader |
In: |
lib/ofac/models/ofac_sdn_loader.rb
|
Parent: | Object |
Loads the most recent file from www.treas.gov/offices/enforcement/ofac/sdn/delimit/index.shtml
# File lib/ofac/models/ofac_sdn_loader.rb, line 9 def self.load_current_sdn_file puts "Reloading OFAC sdn data" puts "Downloading OFAC data from http://www.treas.gov/offices/enforcement/ofac/sdn" yield "Downloading OFAC data from http://www.treas.gov/offices/enforcement/ofac/sdn" if block_given? #get the 3 data files sdn = Tempfile.new('sdn') bytes = sdn.write(Net::HTTP.get(URI.parse('http://www.treasury.gov/ofac/downloads/sdn.pip'))) sdn.rewind if bytes == 0 || convert_line_to_array(sdn.readline).size != 12 puts "Trouble downloading file. The url may have changed." yield "Trouble downloading file. The url may have changed." if block_given? return else sdn.rewind end address = Tempfile.new('sdn') address.write(Net::HTTP.get(URI.parse('http://www.treasury.gov/ofac/downloads/add.pip'))) address.rewind alt = Tempfile.new('sdn') alt.write(Net::HTTP.get(URI.parse('http://www.treasury.gov/ofac/downloads/alt.pip'))) alt.rewind if OfacSdn.connection.kind_of?(ActiveRecord::ConnectionAdapters::MysqlAdapter) puts "Converting file to csv format for Mysql import. This could take several minutes." yield "Converting file to csv format for Mysql import. This could take several minutes." if block_given? csv_file = convert_to_flattened_csv(sdn, address, alt) do |status| yield status if block_given? end bulk_mysql_update(csv_file)do |status| yield status if block_given? end else active_record_file_load(sdn, address, alt)do |status| yield status if block_given? end end sdn.close @address.close @alt.close end