Created
March 23, 2010 10:31
-
-
Save ayosec/341027 to your computer and use it in GitHub Desktop.
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
require 'rubygems' | |
require 'mechanize' | |
def prompt(label, echo = true) | |
`stty -echo` unless echo | |
$stdout.print "#{label}: " | |
$stdout.flush | |
$stdin.readline.strip | |
ensure | |
unless echo | |
`stty echo` | |
puts | |
end | |
end | |
agent = Mechanize.new {|agent| agent.user_agent_alias = 'Linux Firefox' } | |
if ARGV.empty? | |
STDERR.puts "Usage: #$PROGRAM_NAME task1 task2 ... taskN" | |
exit 1 | |
end | |
agent.get('http://www.hiveminder.com') do |page| | |
login = page.form_with(:name => 'loginbox') do |form| | |
form["J:A:F-address-loginbox"] = prompt("Email address") | |
form["J:A:F-password-loginbox"] = prompt("Password", false) | |
end.submit | |
end | |
ARGV.each do |task| | |
print "##{task}: Loading...\r"; $stdout.flush | |
begin | |
agent.get("http://hiveminder.com/task/#{task}/edit") do |page| | |
unless page.root.at("h1.title") | |
puts "Invalid page! Are you loggeed?" | |
next | |
end | |
puts "##{task}: #{page.root.at("h1.title").children.first.text.strip}" | |
input_id = nil | |
page.labels.each do |label| | |
if label.text == "Owner" | |
input_id = label.node.attributes["for"].text | |
break | |
end | |
end | |
if input_id.nil? | |
puts "Owner field not found!" | |
next | |
end | |
catch :task_done do | |
page.forms.each do |form| | |
form.fields.each do |field| | |
if field.node.attributes["id"] and field.node.attributes["id"].text == input_id | |
if field.value != "nobody" | |
puts "Setting owner from #{field.value} to nobody" | |
field.value = "nobody" | |
form.submit | |
end | |
throw :task_done | |
end | |
end | |
end | |
end | |
end | |
rescue Exception => e | |
puts "##{task}: ERROR: #{e}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment