Sha256: 73aef7b27844cf1ec48eba901bb715255d3983fbe07f6da9b3b58d4e7d31318e
Contents?: true
Size: 963 Bytes
Versions: 1
Compression:
Stored size: 963 Bytes
Contents
#!/usr/bin/env ruby require 'open-uri' require 'pstore' require 'tempfile' puts 'downloading...' data = PStore.new('lib/polish_postal_codes.pstore') tmp_file = Tempfile.new('spispna.pdf') tmp_file.write(open('https://www.poczta-polska.pl/hermes/uploads/2013/11/spispna.pdf').read) tmp_file.flush puts 'converting...' system("pdftotext -layout #{tmp_file.path}") data.transaction do File.open("#{tmp_file.path}.txt", 'r').each_line do |line| break if line =~ /Podmioty posiadające odrębne PNA/ next unless line =~ /([0-9]{2}-[0-9]{3})/ t = line.gsub(/\ {2,}/, ' ').split(/ /) data[t[0].strip] ||= { city: t[1].split('(').first.strip, community: t[-3].strip, county: t[-2].strip, province: t[-1].strip } end end at_exit do converted_txt_file_path = "#{tmp_file.path}.txt" File.delete converted_txt_file_path if File.exist? converted_txt_file_path end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polish_postal_codes-0.0.2 | bin/update |