Skip to content

Instantly share code, notes, and snippets.

@mokolabs
Created March 16, 2012 21:18
Show Gist options
  • Save mokolabs/2052763 to your computer and use it in GitHub Desktop.
Save mokolabs/2052763 to your computer and use it in GitHub Desktop.
archive your slicehost invoices
require 'rubygems'
require 'mechanize'
a = Mechanize.new { |agent|
agent.follow_meta_refresh = true
agent.pluggable_parser.pdf = Mechanize::FileSaver
}
a.get('https://manage.slicehost.com/') do |home_page|
# Login
dashboard = home_page.form_with(:action => '/sessions') do |form|
form.email = EMAIL
form.password = PASSWORD
end.submit
# Go to Account page
accounts_page = a.click(dashboard.link_with(:text => 'Account'))
# Go to Invoices page
invoices = a.click(accounts_page.link_with(:text => 'Payments, Balance & Invoices'))
# Save all invoices as HTML
invoices.links_with(:href => /payments\/[0-9]/).each do |link|
filename = link.to_s.split(" on ")[1].match(/(.*), ([0-9]*)/)[2]
filename = filename + "-"
filename = filename + link.to_s.split(" on ")[1].match(/(.*), ([0-9]*)/)[1]
a.click(link).save_as "#{filename}.html"
end
end
@mokolabs
Copy link
Author

Just add your account information on lines 13 and 14, and run it!

@ryanfelton
Copy link

Thank you! I just pulled 6 years of invoices down.

@enkrates
Copy link

Nice!

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