Last active
March 6, 2020 17:01
-
-
Save KruegerDesigns/3382ab8f3d38321a255dca5e6e22b0ee to your computer and use it in GitHub Desktop.
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
require 'uri' | |
require 'net/http' | |
require 'net/https' | |
require 'json' | |
require 'csv' | |
lucid_sites_csv = CSV.parse(File.read("../all-sites.csv"), headers: true) | |
airtable_csv = CSV.open("../import-to-airtable.csv", "wb") | |
airtable_csv << ["Domain Name","Domain Pointed at Einstein?","Has SSL? ...154","Current Git Repo Branch","Active EIS Client?","EIS Primary Domain","Lucid Theme","Lucid Status","Lucid License Expiration","Site Live?"] | |
lucid_sites_csv.each do |lucid_site| | |
theme = lucid_site['Theme'] | |
git_branch = lucid_site['Git Branch'] | |
domain = lucid_site['Domain'] | |
if domain == "Domain" | |
next | |
end | |
lucid_has_ssl = "No" | |
domain_pointed_at_einstein = "No" | |
# ip = "" | |
dig = %x( dig @8.8.8.8 #{domain} ) | |
dig.each_line do |line| | |
if line = line.scan(/(.*)A\s+([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)/) | |
line.each do |l| | |
# ip = "#{l[1]}.#{l[2]}.#{l[3]}.#{l[4]}" | |
if l[4] == "154" | |
lucid_has_ssl = "Yes" | |
end | |
if "#{l[1]}.#{l[2]}" == "69.43" | |
domain_pointed_at_einstein = "Yes" | |
end | |
end | |
end | |
end | |
begin | |
if lucid_has_ssl == "Yes" | |
uri = URI.parse("https://www.#{domain}") | |
else | |
uri = URI.parse("http://www.#{domain}") | |
end | |
request = Net::HTTP::Head.new(uri) | |
if lucid_has_ssl == "Yes" | |
req_options = { | |
use_ssl: uri.scheme == "https", | |
} | |
end | |
response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http| | |
http.request(request) | |
end | |
is_lucid_site = false | |
response.each_header do |key, value| | |
if key == "x-lucid-theme-name" | |
is_lucid_site = true | |
end | |
end | |
http_response = response.code | |
# response.body | |
rescue | |
@error_message = "#{$!}" # no longer a lucid site for this subdomain! | |
airtable_csv << [domain,"No","N/A",git_branch,"N/A","N/A",theme,"N/A","N/A","No"] | |
next | |
end | |
subdomain = domain.split(".").first | |
url = "https://#{subdomain}.site.json" | |
uri = URI(url) | |
response = Net::HTTP.get(uri) | |
begin | |
json = JSON.parse(response) | |
rescue | |
@error_message = "#{$!}" # no longer a lucid site for this subdomain! | |
airtable_csv << [domain,domain_pointed_at_einstein,lucid_has_ssl,git_branch,"N/A","N/A",theme,"N/A","N/A","No"] | |
next | |
end | |
status = "Inactive" | |
if json['status'] == true | |
status = "Active" | |
end | |
expires = '0' | |
if json['expires_on'] != nil | |
expires = json['expires_on'] | |
end | |
if domain_pointed_at_einstein == "Yes" && status == "Active" && is_lucid_site && http_response == "200" | |
site_live = "Yes" | |
else | |
site_live = "No" | |
end | |
airtable_csv << [domain,domain_pointed_at_einstein,lucid_has_ssl,git_branch,"N/A","N/A",theme,status,expires,site_live] | |
puts "=======================" | |
puts "Domain Name: #{domain}" | |
puts "Domain Pointed at Einstein?: #{domain_pointed_at_einstein}" | |
puts "Has SSL? ...154: #{lucid_has_ssl}" | |
puts "Current Git Repo Branch: #{git_branch}" | |
puts "Active EIS Client?: [Airtable]" | |
puts "EIS Primary Domain: [Airtable]" | |
puts "Lucid Theme: #{theme}" | |
puts "Lucid Status: #{status}" | |
puts "Lucid License Expiration: #{expires}" | |
puts "Site Live?: #{site_live}" | |
puts "=======================" | |
puts "" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment