Skip to content

Instantly share code, notes, and snippets.

@oki
Created August 13, 2009 14:04
Show Gist options
  • Select an option

  • Save oki/167196 to your computer and use it in GitHub Desktop.

Select an option

Save oki/167196 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'rubygems'
require 'mechanize'
require 'pp'
user = 'user'
pass = 'pass'
agent = WWW::Mechanize.new { |a|
a.user_agent_alias = 'Mac Safari'
}
page = agent.get('http://www.bikestats.pl/')
login_form = page.forms.first
login_form.login = user
login_form.pass = pass
login_form.checkbox_with(:name => 'remlogged').check
login_form.backto = "http://www.bikestats.pl/"
page = agent.submit(login_form)
if page.content =~ /#{user}.*?zosta\305\202e\305\233 zalogowany/
puts "Zalogowany: #{user}"
else
puts "Nie udalo sie zalogowac"
exit 1
end
page = agent.get("http://www.bikestats.pl/posts/postadd")
trip_form = page.forms[1]
trip_form.title = "Work"
trip_form.km = "12.98"
trip_form.checkbox_with(:value => '7988').check
page = agent.submit(trip_form)
if page.content =~ /Wpis został pomyślnie zapisany/
puts "Wpis dodany!"
else
puts "Jakis problem z dodaniem wpisu"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment