Class: OfacSdnIndividualLoader
- Inherits:
-
Object
- Object
- OfacSdnIndividualLoader
- Defined in:
- app/models/ofac_sdn_individual_loader.rb
Class Method Summary collapse
-
.load_current_sdn_file {|"Downloading OFAC data from https://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx"| ... } ⇒ Object
Loads the most recent file from www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx.
Class Method Details
.load_current_sdn_file {|"Downloading OFAC data from https://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx"| ... } ⇒ Object
Loads the most recent file from www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/ofac_sdn_individual_loader.rb', line 16 def self.load_current_sdn_file puts "Reloading OFAC sdn data" puts "Downloading OFAC data from https://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx" yield "Downloading OFAC data from https://www.treasury.gov/resource-center/sanctions/SDN-List/Pages/default.aspx" if block_given? #get the 3 data files sdn = Tempfile.new('sdn') uri = URI.parse('https://www.treasury.gov/ofac/downloads/sdn.pip') proxy_addr, proxy_port = ENV['http_proxy'].gsub("http://", "").split(/:/) if ENV['http_proxy'] bytes = sdn.write(Net::HTTP::Proxy(proxy_addr, proxy_port).get(uri)) 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::Proxy(proxy_addr, proxy_port).get(URI.parse('https://www.treasury.gov/ofac/downloads/add.pip'))) address.rewind alt = Tempfile.new('sdn') alt.write(Net::HTTP::Proxy(proxy_addr, proxy_port).get(URI.parse('https://www.treasury.gov/ofac/downloads/alt.pip'))) alt.rewind if (defined?(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter) && OfacSdnIndividual.connection.kind_of?(ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter)) || (defined?(ActiveRecord::ConnectionAdapters::JdbcAdapter) && OfacSdnIndividual.connection.kind_of?(ActiveRecord::ConnectionAdapters::JdbcAdapter)) 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 |