Sha256: 63a407d0286a6eb29d5629fbd84e81277c6277f3dea54fb31347fa73aa4afd1c
Contents?: true
Size: 997 Bytes
Versions: 10
Compression:
Stored size: 997 Bytes
Contents
#!/usr/bin/env ruby require 'open-uri' require 'pstore' require 'tempfile' puts 'downloading...' data = PStore.new(File.expand_path('../../lib/polish_postal_codes.pstore', __FILE__)) 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
10 entries across 10 versions & 1 rubygems