Created
August 23, 2009 04:24
-
-
Save rumblex/173155 to your computer and use it in GitHub Desktop.
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 | |
require 'rubygems' | |
require 'fastercsv' | |
require 'json' | |
def jsonify(set) | |
Dir.chdir set | |
images = [] | |
folders = Dir["*/"] | |
folders.each do |folder| | |
# Get all of the files in each entry folder | |
files = Dir["#{folder}*.png"] | |
# Build a team history json | |
File.open("#{folder.slice(0, folder.length-1)}.js", 'w') do |file| | |
file.puts("RumbleSnaps.snaps = " + {'snaps' => files}.to_json + ".snaps") | |
end | |
# Keep the most recent one | |
recent = files.last | |
images << recent if recent | |
end | |
# Write out the recent json | |
File.open('recent.js', 'w') do |file| | |
file.puts("RumbleSnaps.snaps = " + {'snaps' => images}.to_json + ".snaps") | |
end | |
Dir.chdir '..' | |
end | |
def pushify(start) | |
puts "Pushing images to remote" | |
`git pull origin master` | |
`git add .` | |
`git commit -am 'Adding images for #{start}'` | |
`git push origin master` | |
end | |
def make(entry, image, folder, width, height) | |
`mkdir -p #{folder}` | |
`mkdir -p #{folder}/#{entry}` | |
`sips --resampleWidth #{width} --cropToHeightWidth #{width} #{height} --padToHeightWidth #{width} #{height} full/#{image} --out #{folder}/#{image}` | |
`rm #{folder}/#{entry}/recent.png` | |
`ln -s ../#{image} #{folder}/#{entry}/recent.png` | |
end | |
Dir.chdir(File.dirname(__FILE__) + '/snapshots') | |
start = Time.now.strftime("%Y-%m-%d-%H") | |
csv_file = "../dns.csv" | |
FasterCSV.foreach(csv_file) do |row| | |
next if row[0] == "#" | |
time = Time.now.strftime("%Y-%m-%d-%H%M") | |
entry = row[0] | |
team = row[1] | |
site = "#{team}.r09.railsrumble.com" | |
image = "#{entry}/#{team}-#{time}.png" | |
`mkdir -p full` | |
`mkdir -p full/#{entry}` | |
head = `curl --connect-timeout 1 --silent --head http://#{site}` | |
unless head && head.size > 0 | |
puts "Nothing to chomp for site: http://#{site}" | |
next | |
end | |
puts "Chomping snap of site: http://#{site}" | |
`crocodile http://#{site} full/#{image} > /dev/null` | |
make(entry, image, 'small', 90, 90) | |
make(entry, image, 'medium', 300, 300) | |
make(entry, image, 'large', 800, 600) | |
# Keep a recent copy | |
`rm full/#{entry}/recent.png` | |
`ln -s ../#{image} full/#{entry}/recent.png` | |
end | |
jsonify('full') | |
jsonify('small') | |
jsonify('medium') | |
jsonify('large') | |
pushify(start) | |
puts "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment