Last active
October 20, 2015 09:34
-
-
Save lewismarshall/dff96a4078208034afea to your computer and use it in GitHub Desktop.
Selectivly parse Pingdom by region or country code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'open-uri' | |
require 'nokogiri' | |
PINGDOM_XPATH = '//item[country/@code="%s"]/ip/text()' | |
EUROPE_CODES = 'AT,CH,CZ,DK,GB,DE,FR,IE,IT,NL,SE' | |
pingdom_doc = Nokogiri::HTML(open('https://www.pingdom.com/rss/probe_servers.xml')) | |
country_codes_ary = ARGV[0].split(',') | |
format = ARGV[1] | |
country_codes_ary.each do |code| | |
if code == 'europe' | |
country_codes_ary = country_codes_ary | EUROPE_CODES.split(',') | |
end | |
end | |
country_codes_ary.each do |code| | |
pingdom_doc.xpath(PINGDOM_XPATH % code).each do |item| | |
if format | |
puts format % item.to_s | |
else | |
puts item.to_s | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Query by region and country:
get_pingdom_ips.rb europe,US
Query with format string:
get_pingdom_ips.rb europe,US " - %s"