summaryrefslogtreecommitdiff
blob: 02b94184d61d9f2d67bc3b9cbbfaca5a03f8513b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/ruby
require 'rexml/document'
require 'open-uri'

MIRROR_DATA="https://api.gentoo.org/mirrors/distfiles.xml"

m = URI.parse(MIRROR_DATA).read
x = REXML::Document.new(m)

def normalize_mirror(xml_elem)
  return xml_elem.texts().join(' ').sub(/\/+$/, '') + '/'
end

def select_mirror(xml_elem)
  1
end

REXML::XPath.each(x, '//*/mirrorgroup[@country]') {|el|
  country = el.attributes['country']

  el.each_element('mirror/uri/') do |uri_elem|
    puts "#{country.downcase} #{normalize_mirror(uri_elem)}" if select_mirror(uri_elem)
  end
}