Skip to content

Instantly share code, notes, and snippets.

@lewismarshall
Last active October 20, 2015 09:34
Show Gist options
  • Save lewismarshall/dff96a4078208034afea to your computer and use it in GitHub Desktop.
Save lewismarshall/dff96a4078208034afea to your computer and use it in GitHub Desktop.
Selectivly parse Pingdom by region or country code
#!/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
@lewismarshall
Copy link
Author

Query by region and country:
get_pingdom_ips.rb europe,US
Query with format string:
get_pingdom_ips.rb europe,US " - %s"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment