Skip to content

Instantly share code, notes, and snippets.

@mendicantx
Created March 25, 2010 21:50
Show Gist options
  • Save mendicantx/344172 to your computer and use it in GitHub Desktop.
Save mendicantx/344172 to your computer and use it in GitHub Desktop.
# Note that the unzip app that i'm using is in my path from an Oracle installation.
# You can get unzip here: http://info-zip.org/UnZip.html and put it in your path
# Or replace the `unzip -o #{zipfile}` command with the unzip command line of your choice
# Personally, I also have an update.bat file which I use to run this script which I have indexed in launchy
require 'uri'
require 'net/http'
require 'fileutils'
def get_http
return Net::HTTP.start("builds.hibernatingrhinos.com")
end
def download(link, zipfile)
puts link
Net::HTTP.start(URI.parse(link).host) do |http|
file = open(zipfile, "wb")
resp = http.get(URI.parse(link).path)
file.write(resp.body)
file.close
end
end
def unzip(zipfile)
`unzip -o #{zipfile}`
end
def get_redirected_filename(link)
new_link = ""
get_http.get(link).body.split("\r\n").each do |line|
if (line.index("a href").nil? == false)
new_link = line.split("\"")[1]
end
end
return new_link
end
def download_and_unzip(link, zipfile)
FileUtils.rm zipfile if (File.exists?(zipfile))
redirected_filename = get_redirected_filename(link.split("\"")[1])
download(redirected_filename, zipfile)
unzip zipfile
end
resp = get_http.get("/builds/NHProf")
is_not_downloaded = true
resp.body.split("\r\n").each do |line|
if (line.index("NHibernate.Profiler-Build").nil? == false && is_not_downloaded)
download_and_unzip line, "nhprof.zip"
is_not_downloaded = false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment