Created
March 16, 2012 21:18
-
-
Save mokolabs/2052763 to your computer and use it in GitHub Desktop.
archive your slicehost invoices
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you! I just pulled 6 years of invoices down.