Skip to content

Instantly share code, notes, and snippets.

@berislavbabic
Created January 26, 2011 00:22
Show Gist options
  • Save berislavbabic/795991 to your computer and use it in GitHub Desktop.
Save berislavbabic/795991 to your computer and use it in GitHub Desktop.
Script to download all VM images from stacklet.com, only if you are a paying customer of course.
require 'rubygems'
require 'mechanize'
require 'nokogiri'
username = USERNAME
password = PASSWORD
scrape_urls = {'solus' => 'http://stacklet.com/downloads/templates/solus',
'qemu' => 'http://stacklet.com/downloads/templates/qemu',
'qemu_2' => 'http://stacklet.com/downloads/templates/qemu?page=1',
'emi' => 'http://stacklet.com/downloads/templates/emi',
'xva' => 'http://stacklet.com/downloads/templates/xva',
'vmdk' => 'http://stacklet.com/downloads/templates/vmdk',
'vmdk_2' => 'http://stacklet.com/downloads/templates/vmdk?page=1',
'xen3' => 'http://stacklet.com/downloads/templates/xen3',
'xen3_2' => 'http://stacklet.com/downloads/templates/xen3?page=1'}
a = Mechanize.new
# stacklet is slow sometimes...
a.read_timeout = 500
a.get('http://stacklet.com/') do |page|
# login
page.form_with(:action => '/node?destination=node') do |f|
f["name"] = username
f["pass"] = password
end.click_button
# get download links
scrape_urls.each do |key, value|
vmdk_page = a.get(value)
vmdk_page.search('//td[5]').each do |links|
links.css('a').each do |link|
puts link
file_page = a.get('http://stacklet.com' + link["href"])
links_div = file_page.search('//div[@id="content"]//a')
links_div.each do |l|
file = File.open('stacklet_links_' + key, 'a')
# shows only md5 and tar files in links so you can download them easily with wget
if (l["href"] =~ /tar.gz.md5/ || l["href"] =~ /tar.bz2.md5/)
dl_link = l["href"]
file.write dl_link + "\n"
end
if l["href"] =~ /s4.stacklet.com/ && (l["href"] =~ /tar.gz/ || l["href"] =~ /tar.bz2/)
dl_link = l["href"]
file.write dl_link + "\n"
file.close
break
end
file.close
end
end
end
end
end
@berislavbabic
Copy link
Author

A friend of mine bought stacklet.com account so we could set up some vm's hassle free.
So i created this download script, to get all the images, before the subscription runs out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment