Last active
December 3, 2016 05:12
-
-
Save qrkourier/601fd1c773df9baede99bca5dd1ec377 to your computer and use it in GitHub Desktop.
find equivalent domain names for the Stack Exchange network of sites for LastPass account settings
This file contains hidden or 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 | |
# | |
# [this lives here now](https://github.com/qrkourier/stackdom/blob/master/bin/stackdom.rb) | |
# | |
# slurp some XML over HTTP and parse to find equivalent domain | |
# names for the Stack Exchange network of sites | |
# | |
# shell $ gem install xml-simple domainatrix | |
# | |
# tested with >= Ruby 1.9.2 | |
# | |
# stdlib | |
require 'net/http' | |
# gems | |
require 'rubygems' | |
require 'xmlsimple' | |
require 'domainatrix' | |
equivalent_domains = [] | |
# get the list of SE sites from their XML feed | |
feed = 'http://stackexchange.com/feeds/sites' | |
doc = Net::HTTP.get_response(URI.parse(feed)).body | |
# parse the document to compose a data object | |
data = XmlSimple.xml_in(doc) | |
# iterate over each id in the entry array and join the top-level and | |
# registrar-assigned domain names, discarding the subdomain and path parts, and | |
# push the result into an array | |
data['entry'].each do |entry| | |
url = Domainatrix.parse(entry["id"][0]) | |
equivalent_domains << url.domain + "." + url.public_suffix | |
end | |
# print a comma-separated list of unique domain names | |
puts equivalent_domains.uniq * "," |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment