Skip to content

Commit

Permalink
remove old sites, and catch any REST errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Dru Ibarra authored and Dru Ibarra committed Nov 23, 2010
1 parent 2d17cf7 commit 4dcca36
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions bin/rt-client.rb
Expand Up @@ -4,22 +4,43 @@

SERVER_URL = "http://pagerank.gorillanation.com"

puts "> Importing sites from Asset Tracker ..."
puts "> Syncing with sites from Asset Tracker ..."

# get hosts from RT
hosts = `rt list -t asset "Type='Site' AND Status='production'" | awk -F ":" '{print $2}' | awk '{print $1}'`.split

# get sites from PageRankDashboard
# get sites from PageRankDashboard and hash them by name
site_hash = {}
response = RestClient.get "#{SERVER_URL}/sites.json", :content_type => 'application/json', :accept => :json
site_names = JSON.parse(response).collect{|site| site['name'] }
JSON.parse(response).map{|site_data| site_hash[site_data['name']] = site_data}
site_names = site_hash.keys

new_sites = hosts - site_names
decomissioned_sites = site_names - hosts

# add new sites from RT to page rank
new_sites.each do |site_name|
next if site_name =~ /gorillanation\.com/ # skip sites with GN domains
puts "+ Importing #{site_name}"
print "+ Importing #{site_name}..."
json_string = { :site => { :name => site_name } }.to_json
RestClient.post "#{SERVER_URL}/sites.json", json_string, :content_type => :json, :accept => :json
begin
RestClient.post "#{SERVER_URL}/sites.json", json_string, :content_type => :json, :accept => :json
puts "OK"
rescue => e
puts "ERROR"
end
end

puts "> Import complete"
# remove decomissioned sites
decomissioned_sites.each do |site_name|
print "- Removing #{site_name}..."
site_id = site_hash[site_name]['id']
begin
RestClient.delete "#{SERVER_URL}/sites/#{site_id}.json", :content_type => :json, :accept => :json
puts "OK"
rescue => e
puts "ERROR"
end
end

puts "> Sync complete"

0 comments on commit 4dcca36

Please sign in to comment.