Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby
require 'open-uri'
url = 'http://ycombinator.com/faq.html'
body = open(url){|f| f.read}
link_text = body.match(/The ones that are currently launched are:.*?<p>/m).to_s
domains = link_text.gsub(/<!--.*?-->/m, '').scan(%r{<a href="http://([^"]+)"})
orgs = {}
domains.each do |c|
whois = `host -t a #{c} | grep 'has address' | cut -f 4 -d ' ' | xargs -n 1 whois`
org = if o = whois.grep(/OrgName/).first
o.sub(/OrgName:\s/, '').strip
else
whois.split("\n").first.split('(')[0].strip.sub(/\s+[A-Z\-\d]+$/, '')
end
(orgs[org] ||= []) << c
end
max_size = orgs.sort_by{|k, v| k.size}.last.first.size
orgs.sort_by{|k, v| v.size}.reverse.each do |o, ds|
puts "%-#{max_size}s %5s" % [o, ds.size]
ds.sort.each {|d| puts "\t#{d}"}
end
puts
puts "%-#{max_size}s %5s" % ["Total # of Domains", domains.size]
puts "%-#{max_size}s %5s" % ["Total # of Providers", orgs.size]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.