Sha256: 9a266d152758710d58e24fbe96e24db8541755b4a65f34f2e0e66cb1bc838659
Contents?: true
Size: 1.19 KB
Versions: 10
Compression:
Stored size: 1.19 KB
Contents
#!/usr/bin/env ruby require 'rubygems' require 'open-uri' require 'nokogiri' require 'yaml' require 'zip' # Download XML file from http://www.archiwum.uke.gov.pl/tablice/NumerPlmn-list.do?execution=e5s1 data = {} Zip::InputStream.open(StringIO.new(open('http://www.archiwum.uke.gov.pl/tablice/xml/T2-PLMN_T9-MVNO.xml.zip').read)) do |io| io.get_next_entry doc = Nokogiri::XML.parse(io.read) doc.xpath('//numery/plmn').each do |node| number = node.xpath('numer').inner_text operator = node.xpath('operator').inner_text m = number.match /([0-9]+)\(([0-9,-]+)\)/ numbers = [] data[operator] = [] unless data.has_key?(operator) if m number = m[1] m[2].split(',').each do |i| range = i.split('-') if range.length > 1 Range.new(range[0].to_i,range[1].to_i == 0 ? 10 : range[1].to_i).each do |i| numbers.push "#{number}#{i == 10 ? 0 : i}" end else numbers.push "#{number}#{i}" end end data[operator].push numbers data[operator].flatten!(1) else data[operator].push number end end end File.open("yaml/operators.yml", "w") do |file| file.write data.to_yaml end
Version data entries
10 entries across 10 versions & 1 rubygems