ofac 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ofac/models/ofac_sdn_loader.rb +11 -16
- data/lib/ofac/version.rb +1 -1
- data/test/files/valid_flattened_file.csv +19 -19
- data/test/ofac_sdn_loader_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddd5f199e084fcb682c6c60d792a5e5a422a2c8c
|
4
|
+
data.tar.gz: 626fc7b9518f0c637bc1afd137d5425033445634
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c7f44b8c5124fdbc4cc2dc6ced138f74a77d5b7a09c494190e6c05a0796c417fd4369e8f5e8bf1d3918e25b06dd7eba5e09a9d69270a4903c30bbb2695614e23
|
7
|
+
data.tar.gz: 8dae00b23c77d145de925cd8977390bb1f28d10a3052383ffa5c05ff71fed68264490333dbf51ad110f2a6874a8fa07d5a1491074b6c226b2addd730ae6fd231
|
@@ -12,8 +12,6 @@ rescue Gem::LoadError, LoadError
|
|
12
12
|
end
|
13
13
|
|
14
14
|
class OfacSdnLoader
|
15
|
-
|
16
|
-
|
17
15
|
#Loads the most recent file from http://www.treas.gov/offices/enforcement/ofac/sdn/delimit/index.shtml
|
18
16
|
def self.load_current_sdn_file
|
19
17
|
puts "Reloading OFAC sdn data"
|
@@ -22,7 +20,6 @@ class OfacSdnLoader
|
|
22
20
|
#get the 3 data files
|
23
21
|
sdn = Tempfile.new('sdn')
|
24
22
|
uri = URI.parse('http://www.treasury.gov/ofac/downloads/sdn.pip')
|
25
|
-
|
26
23
|
proxy_addr, proxy_port = ENV['http_proxy'].gsub("http://", "").split(/:/) if ENV['http_proxy']
|
27
24
|
|
28
25
|
bytes = sdn.write(Net::HTTP::Proxy(proxy_addr, proxy_port).get(uri))
|
@@ -70,13 +67,13 @@ class OfacSdnLoader
|
|
70
67
|
#and removes " chars.
|
71
68
|
def self.clean_file_string(line)
|
72
69
|
line.gsub!(/-0-(\s)?/, '')
|
73
|
-
line.gsub!(
|
74
|
-
line
|
70
|
+
line.gsub!(/[\n\r"]/, '')
|
71
|
+
line
|
75
72
|
end
|
76
73
|
|
77
74
|
#split the line into an array
|
78
75
|
def self.convert_line_to_array(line)
|
79
|
-
clean_file_string(line).split('|') unless line.nil?
|
76
|
+
clean_file_string(line).split('|', -1) unless line.nil?
|
80
77
|
end
|
81
78
|
|
82
79
|
#return an 2 arrays of the records matching the sdn primary key
|
@@ -156,10 +153,7 @@ class OfacSdnLoader
|
|
156
153
|
end
|
157
154
|
|
158
155
|
def self.convert_hash_to_mysql_import_string(record_hash)
|
159
|
-
|
160
|
-
new_line = "``|" +
|
161
|
-
# :name
|
162
|
-
"`#{record_hash[:name]}`|" +
|
156
|
+
new_line = "`#{record_hash[:name]}`|" +
|
163
157
|
# :sdn_type
|
164
158
|
"`#{record_hash[:sdn_type]}`|" +
|
165
159
|
# :program
|
@@ -195,9 +189,9 @@ class OfacSdnLoader
|
|
195
189
|
# :alternate_identity_remarks
|
196
190
|
"`#{record_hash[:alternate_identity_remarks]}`|" +
|
197
191
|
#:created_at
|
198
|
-
"`#{
|
192
|
+
"`#{@db_time}`|" +
|
199
193
|
# updated_at
|
200
|
-
"`#{
|
194
|
+
"`#{@db_time}`" + "\n"
|
201
195
|
|
202
196
|
new_line
|
203
197
|
end
|
@@ -206,13 +200,14 @@ class OfacSdnLoader
|
|
206
200
|
@address = address_file
|
207
201
|
@alt = alt_file
|
208
202
|
|
203
|
+
@db_time = Time.now.to_s(:db)
|
204
|
+
|
209
205
|
csv_file = Tempfile.new("ofac") # create temp file for converted csv format.
|
210
|
-
|
206
|
+
#get the first line from the address and alt files
|
211
207
|
@current_address_hash = address_text_to_hash(@address.gets)
|
212
208
|
@current_alt_hash = alt_text_to_hash(@alt.gets)
|
213
209
|
|
214
210
|
start = Time.now
|
215
|
-
|
216
211
|
sdn_file.each_with_index do |line, i|
|
217
212
|
|
218
213
|
#initialize the address and alt atributes to empty strings
|
@@ -324,13 +319,13 @@ class OfacSdnLoader
|
|
324
319
|
yield "Deleting all records in ofac_sdn..." if block_given?
|
325
320
|
|
326
321
|
#OFAC data is a complete list, so we have to dump and load
|
327
|
-
OfacSdn.
|
322
|
+
OfacSdn.connection.execute("TRUNCATE ofac_sdns;")
|
328
323
|
|
329
324
|
puts "Importing into Mysql..."
|
330
325
|
yield "Importing into Mysql..." if block_given?
|
331
326
|
|
332
327
|
mysql_command = <<-TEXT
|
333
|
-
LOAD DATA LOCAL INFILE '#{csv_file.path}' REPLACE INTO TABLE ofac_sdns FIELDS TERMINATED BY '|' ENCLOSED BY "`" LINES TERMINATED BY '\n';
|
328
|
+
LOAD DATA LOCAL INFILE '#{csv_file.path}' REPLACE INTO TABLE ofac_sdns FIELDS TERMINATED BY '|' ENCLOSED BY "`" LINES TERMINATED BY '\n' (name, sdn_type, program, title, vessel_call_sign, vessel_type, vessel_tonnage, gross_registered_tonnage, vessel_flag, vessel_owner, remarks, address, city, country, address_remarks, alternate_identity_type, alternate_identity_name, alternate_identity_remarks, created_at, updated_at);
|
334
329
|
TEXT
|
335
330
|
|
336
331
|
OfacSdn.connection.execute(mysql_command)
|
data/lib/ofac/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
VERSION = '2.0.
|
1
|
+
VERSION = '2.0.4'
|
@@ -1,19 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
`ABASTECEDORA NAVAL Y INDUSTRIAL, S.A.`|``|`CUBA`|``|``|``|``|``|``|``|``|``|``|`Panama`|``|``|``|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
2
|
+
`ABDELNUR`|` Nury de Jesus`|`individual`|`CUBA`|``|``|``|``|``|``|``|``|``|`Panama`|``|`aka`|`VIAJES GUAMA TOURS`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
3
|
+
`HERNANDEZ, Oscar`|`individual`|`CUBA`|``|``|`Unknown vessel type`|``|``|``|`Acechilly Navigation Co., Malta`|``|`123 Somewhere Ln`|`Clearwater`|`United States`|``|`aka`|`HERNANDEZ, Oscar Grouch`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
4
|
+
`HERNANDEZ, Oscar`|`individual`|`CUBA`|``|``|`Unknown vessel type`|``|``|``|`Acechilly Navigation Co., Malta`|``|`123 Somewhere Ln`|`Clearwater`|`United States`|``|`aka`|`Alternate Name`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
5
|
+
`LOPEZ MENDEZ, Luis Eduardo`|`individual`|`CUBA`|``|``|`Unknown vessel type`|``|``|``|`Acefrosty Shipping Co., Malta`|``|``|``|``|``|``|``|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
6
|
+
`ACEFROSTY SHIPPING CO., LTD.`|``|`CUBA`|``|``|``|``|``|``|``|``|``|``|``|``|`aka`|`AVIA IMPORT`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
7
|
+
`AEROCARIBBEAN AIRLINES`|``|`CUBA`|``|``|``|``|``|``|``|``|``|``|``|``|`aka`|`BNC`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
8
|
+
`AEROCARIBBEAN AIRLINES`|``|`CUBA`|``|``|``|``|``|``|``|``|``|``|``|``|`aka`|`NATIONAL BANK OF CUBA`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
9
|
+
`AEROCARIBBEAN AIRLINES`|``|`CUBA`|``|``|``|``|``|``|``|``|``|``|``|``|`aka`|`BNC`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
10
|
+
`AEROTAXI EJECUTIVO, S.A.`|``|`CUBA`|``|``|``|``|``|``|``|``|``|`Managua`|`Nicaragua`|``|``|``|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
11
|
+
`AEROTAXI EJECUTIVO, S.A.`|``|`CUBA`|``|``|``|``|``|``|``|``|`Bal Harbour Shopping Center, Via Italia`|`Panama City`|`Panama`|``|``|``|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
12
|
+
`AGENCIA DE VIAJES GUAMA`|``|`CUBA`|``|``|``|``|``|``|``|``|`Avenida de Concha, Espina 8, E-28036`|`Madrid`|`Spain`|``|`aka`|`NATIONAL BANK OF CUBA`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
13
|
+
`AGENCIA DE VIAJES GUAMA`|``|`CUBA`|``|``|``|``|``|``|``|``|``|``|``|``|`aka`|`NATIONAL BANK OF CUBA`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
14
|
+
`AGUIAR, Raul`|`individual`|`CUBA`|`Director, Banco Nacional de Cuba`|``|``|``|``|``|``|`; Director, Banco Nacional de Cuba.`|``|``|`Italy`|``|`aka`|`BNC`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
15
|
+
`AGUIAR, Raul`|`individual`|`CUBA`|`Director, Banco Nacional de Cuba`|``|``|``|``|``|``|`; Director, Banco Nacional de Cuba.`|``|``|`Italy`|``|`aka`|`NATIONAL BANK OF CUBA`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
16
|
+
`AGUIAR, Raul`|`individual`|`CUBA`|`Director, Banco Nacional de Cuba`|``|``|``|``|``|``|`; Director, Banco Nacional de Cuba.`|``|``|`Panama`|``|`aka`|`BNC`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
17
|
+
`AGUIAR, Raul`|`individual`|`CUBA`|`Director, Banco Nacional de Cuba`|``|``|``|``|``|``|`; Director, Banco Nacional de Cuba.`|``|``|`Panama`|``|`aka`|`NATIONAL BANK OF CUBA`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
18
|
+
`AGUIAR, Raul`|`individual`|`CUBA`|`Director, Banco Nacional de Cuba`|``|``|``|``|``|``|`; Director, Banco Nacional de Cuba.`|`1840 West 49th Street`|``|`United States`|``|`aka`|`BNC`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
19
|
+
`AGUIAR, Raul`|`individual`|`CUBA`|`Director, Banco Nacional de Cuba`|``|``|``|``|``|``|`; Director, Banco Nacional de Cuba.`|`1840 West 49th Street`|``|`United States`|``|`aka`|`NATIONAL BANK OF CUBA`|``|`2009-05-06 15:55:24`|`2009-05-06 15:55:24`
|
@@ -30,7 +30,7 @@ class OfacSdnLoaderTest < Test::Unit::TestCase
|
|
30
30
|
csv_line = generated_file[i]
|
31
31
|
correctly_formatted_record_array = line.split('|')
|
32
32
|
csv_record_array = csv_line.split('|')
|
33
|
-
(0..
|
33
|
+
(0..17).each do |i| #skip indices 19 and 20, they are the created_at and updated_at fields, they will never match.
|
34
34
|
assert_equal correctly_formatted_record_array[i], csv_record_array[i]
|
35
35
|
end
|
36
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ofac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Tyll
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|