Created
April 29, 2015 22:02
-
-
Save davebrace/be25f2b343f1288b2895 to your computer and use it in GitHub Desktop.
Update a spreadsheet of company websites with if they use Google Apps
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
require "csv" | |
require "public_suffix" | |
require "active_support/all" | |
require "resolv" | |
def parse_domain(url) | |
return url unless url.present? | |
domain = url.strip.match(/\A(https?:\/\/(www\.)?)?([^\/]*)\/?/i)[3].downcase | |
parsed_domain = PublicSuffix.parse(domain).domain | |
rescue PublicSuffix::DomainInvalid | |
return "" | |
end | |
def site_uses_google_apps?(site_url) | |
return "" if site_url.blank? | |
domain = parse_domain(site_url) | |
begin | |
!!(Resolv::DNS.new.getresource(domain, Resolv::DNS::Resource::IN::MX).exchange.to_s =~ /google/i) | |
rescue => e | |
"" | |
end | |
end | |
CSV.open("companies_out.csv", "wb") do |csv| | |
CSV.foreach("companies.csv").each_with_index do |row, i| | |
csv << [row, "uses_google_apps"].flatten and next if i == 0 | |
url = row[2] | |
puts url | |
uses_google_apps = site_uses_google_apps?(url) | |
write_row = [row, uses_google_apps].flatten | |
csv << write_row | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment