blz 0.2.0.20181203 → 0.2.0.20190603

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 14a7cdfb274ff2c30e35b413785ecb8030332e34
4
- data.tar.gz: 48fe40a29f5ae6bb7bf06531938fcbadba64f608
3
+ metadata.gz: b10c9a3ddad85875050f3f6aed75714a09692a95
4
+ data.tar.gz: 971d1fa6f38e48ec43fc90a7571f8f473383ef45
5
5
  SHA512:
6
- metadata.gz: f062375007f31493bf55be7c84e09882e26cb25cb5a1c5d8fabd067feb53478287ff0d2a47a9fd61922391050b3cb13d23249eea1f462d02a3ffe126eecded56
7
- data.tar.gz: 7848454bc30130b6a855e598a93bb61c6ae73a8d4822a7d8364b7bffdf92cc3e45657c2ae67235064954d85df20ce4da6443866d1a04aacf59d32c45834798f8
6
+ metadata.gz: 14a2e5ffcbddf0c97d0431517a82effa37e9bc824be630cfb84f23ee82b1459b4c08ff9aac740a529a4327afd3c5f007259c2f892b6fdc95a44d3ad8e0486b78
7
+ data.tar.gz: 5cb61246b47a9903f788b175da47233474e9e2ac82f025098cd1aadc93e72817d743e271787a266e9e678164607a0f393fd12c0436a82175b704d9e2c82e7b9e
@@ -1,3 +1,8 @@
1
+ # 0.2.0.20190603, releases 2019-05-03
2
+
3
+ * BLZ data file updated
4
+ * the previous cycle (20190304) did not contain updates
5
+
1
6
  # 0.2.0.20181203, released 2018-11-01
2
7
 
3
8
  * BLZ data file updated
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ end
9
9
  group :development do
10
10
  gem "mechanize"
11
11
  gem "nokogiri"
12
+ gem "rubyzip", "~> 1.2"
12
13
  end
@@ -4,7 +4,7 @@ extra_rdoc_files = ['CHANGELOG.md', 'LICENSE', 'README.md']
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = 'blz'
7
- s.version = '0.2.0.20181203'
7
+ s.version = '0.2.0.20190603'
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.summary = "BLZ (Bankleitzahlen) for Ruby"
10
10
 
Binary file
@@ -3,6 +3,7 @@
3
3
  require "mechanize"
4
4
  require "logger"
5
5
  require "zlib"
6
+ require "zip"
6
7
 
7
8
  if (f = File.expand_path("~/.extranet")) && File.exist?(f)
8
9
  username, password = File.read(f).strip.split(":", 2)
@@ -44,9 +45,10 @@ begin
44
45
  sleep 1
45
46
  page = agent.get NAVIGATION[:table]
46
47
 
47
- target_link = page.links.find do |link|
48
- !!(link.text.strip =~ /BLZ_\d{8}.txt/)
49
- end
48
+ target_link = page.links
49
+ .select {|link| !!(link.text.strip =~ /BLZ_\d{8}.zip/) }
50
+ .sort_by {|link| link.text.strip }
51
+ .last
50
52
 
51
53
  if !target_link
52
54
  logger.info("no new download found")
@@ -54,7 +56,7 @@ begin
54
56
  end
55
57
 
56
58
  name = target_link.text.strip
57
- if name == format("BLZ_%4d%02d%02d.txt", last_match[:y].to_i, last_match[:m].to_i, last_match[:d].to_i)
59
+ if name == format("BLZ_%4d%02d%02d.zip", last_match[:y].to_i, last_match[:m].to_i, last_match[:d].to_i)
58
60
  logger.info("no matching link found")
59
61
  exit 0
60
62
  end
@@ -63,21 +65,29 @@ begin
63
65
  sleep 1
64
66
  blz = agent.get(target_link.href)
65
67
 
66
- name_match = name.match(/BLZ_(?<y>\d{4})(?<m>\d\d)(?<d>\d\d)\.txt$/)
68
+ name_match = name.match(/BLZ_(?<y>\d{4})(?<m>\d\d)(?<d>\d\d)\.zip$/)
67
69
  target_name = format("../data/%4d_%02d_%02d.tsv.gz", name_match[:y].to_i, name_match[:m].to_i, name_match[:d].to_i)
68
70
  target_file = File.expand_path(target_name, __dir__)
69
71
 
70
- logger.info("reformatting, saving as #{target_file}")
71
- Zlib::GzipWriter.open(target_file, Zlib::BEST_COMPRESSION) do |gz|
72
- while line = blz.body_io.gets
73
- line = line.encode(Encoding::UTF_8, Encoding::ISO_8859_15).chomp!
74
- if line.length != METRIC_LEN
75
- logger.error("expected line length #{METRIC_LEN}, got #{line.length} in '#{line}'")
76
- next
72
+ logger.info("extracting ZIP file")
73
+ Zip::File.open_buffer(blz.body).each do |entry|
74
+ next unless entry.name == "BLZ.txt"
75
+ logger.info("found BLZ data")
76
+
77
+ entry.get_input_stream do |stream|
78
+ logger.info("reformatting, saving as #{target_file}")
79
+ Zlib::GzipWriter.open(target_file, Zlib::BEST_COMPRESSION) do |gz|
80
+ while line = stream.gets
81
+ line = line.encode(Encoding::UTF_8, Encoding::ISO_8859_15).chomp!
82
+ if line.length != METRIC_LEN
83
+ logger.error("expected line length #{METRIC_LEN}, got #{line.length} in '#{line}'")
84
+ next
85
+ end
86
+
87
+ i = 0
88
+ gz.puts METRIC.inject([]) {|s, m| s << line[i ... (i+=m)].strip }.join("\t")
89
+ end
77
90
  end
78
-
79
- i = 0
80
- gz.puts METRIC.inject([]) {|s, m| s << line[i ... (i+=m)].strip }.join("\t")
81
91
  end
82
92
  end
83
93
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0.20181203
4
+ version: 0.2.0.20190603
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oliver Eilhard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-11-01 00:00:00.000000000 Z
12
+ date: 2019-05-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -87,6 +87,7 @@ files:
87
87
  - data/2018_06_04.tsv.gz
88
88
  - data/2018_09_03.tsv.gz
89
89
  - data/2018_12_03.tsv.gz
90
+ - data/2019_06_03.tsv.gz
90
91
  - lib/blz.rb
91
92
  - lib/blz/bank.rb
92
93
  - scripts/Makefile