Created
September 12, 2012 06:42
-
-
Save ymrl/3704741 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 'mechanize' | |
require 'pit' | |
config = Pit.get("keiojp",:require => { | |
"account" => "Your keio.jp account", | |
"password" => "Your keio.jp password" | |
}) | |
@agent = Mechanize.new | |
@agent.max_history = 5 | |
@agent.get 'https://authserv2.hc.keio.ac.jp/login.html' | |
@form = @agent.page.forms[0] | |
@form.field('name').value = config["account"] | |
@form.field('pass').value = config["password"] | |
def authorize | |
begin | |
@form.submit | |
rescue | |
sleep 60 | |
retry | |
end | |
end | |
authorize | |
refresh_uri = @agent.page.meta_refresh.first.uri | |
loop do | |
begin | |
puts "getting #{refresh_uri}" | |
@agent.get refresh_uri | |
rescue | |
sleep 60 | |
authorize | |
retry | |
end | |
sleep 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment