Created
May 26, 2011 14:27
-
-
Save mbailey/993252 to your computer and use it in GitHub Desktop.
Download all your blinksale invoices as PDFs
This file contains 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 'highline/import' | |
require 'mechanize' | |
require 'uri' | |
# Get details | |
domain = ask("your blinksale domain prefix") { |q| q.default = 'mikebailey'} + '.blinksale.com' | |
login_page_url = "https://#{domain}/sessions/new" | |
invoice_list_url = "https://#{domain}/invoices/all/date/2001-01-01/2015-12-31" | |
agent = Mechanize.new | |
# agent.user_agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; .NET CLR 3.0.04506)" | |
agent.pluggable_parser.pdf = Mechanize::FileSaver | |
# Login to BlinkSale | |
page = agent.get(login_page_url) | |
form = page.forms.first | |
form.username = ask("your blinksale username") { |q| q.default = 'mbailey' } | |
form.password = ask("your blinksale password") { |q| q.echo = false; } | |
page = agent.submit form | |
# Grab list of your invoices | |
invoice_list = agent.get(invoice_list_url) | |
# Download all the PDF's | |
links = invoice_list.links_with(:href => /invoices\/\d+/).collect { |link| | |
link.uri.to_s + '.pdf' | |
}.compact | |
links.each {|link| agent.get(link) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment