Skip to content

Instantly share code, notes, and snippets.

@deepakjois
Created August 29, 2009 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deepakjois/177553 to your computer and use it in GitHub Desktop.
Save deepakjois/177553 to your computer and use it in GitHub Desktop.
Script to download CSV export of Bookjetty 'wanted' books data
# Usage : ruby bookjetty.rb username password filename_to_save
require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new
agent.user_agent = "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"
page = agent.get("http://www.bookjetty.com")
login_form = page.forms[1]
# Login
login_form.username = ARGV[0]
login_form.password = ARGV[1]
page = login_form.submit(login_form.buttons.first)
# Navigate to export form
page = agent.click page.links_with(:href => "/account/edit_profile")[0]
page = agent.click page.links_with(:href => "/account/export_books")[0]
# Fill up download form
download_form = page.forms[1]
download_form.field_with(:name => 'category[]').options[0].unselect
download_form.field_with(:name => 'category[]').options[1].select
# Download CSV and save
page = download_form.submit
File.open(ARGV[2], "w") do |f|
f.write page.body
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment