Created
December 11, 2010 17:53
-
-
Save rick/737505 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'mechanize' | |
require 'optparse' | |
options = {} | |
op = OptionParser.new do |opts| | |
opts.on('-f=FILE', '--file=FILE', "Write output to specified file.") do |f| | |
options[:file] = f | |
end | |
opts.on('-p=ID', '--projectid=ID', 'PT project id number') do |p| | |
options[:project_id] = p | |
end | |
opts.on_tail('-h', '--help', 'show this message') do | |
puts opts | |
exit | |
end | |
end | |
op.parse! | |
username = ENV['PT_USER'] | |
password = ENV['PT_PASS'] | |
raise "Must specify Pivotal Tracker user name via PT_USER environment variable.\n"+op.to_s unless | |
username and username != '' | |
raise "Must specify Pivotal Tracker password via PT_PASS environment variable.\n"+op.to_s unless | |
password and password != '' | |
outfile = options[:file] | |
project_id = options[:project_id] | |
raise op.to_s unless outfile and outfile != '' | |
raise op.to_s unless project_id and project_id != '' | |
agent = Mechanize.new | |
page = agent.get("https://www.pivotaltracker.com/projects/#{project_id}") | |
sign_in = page.forms.first | |
sign_in.field_with(:name => 'credentials[username]').value = username | |
sign_in.field_with(:name => 'credentials[password]').value = password | |
project_page = agent.submit(sign_in, sign_in.buttons.first) | |
export_page = project_page.link_with(:text => "Export CSV").click | |
export_form = export_page.forms.first | |
csv = agent.submit(export_form, export_form.buttons.first) | |
csv.save_as(outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment