iTunes Connectメンテナンス

iTunes Connectのメンテナンスで、以前ご紹介したScriptがそのままでは使えなくなったので、修正方法のご紹介。
http://d.hatena.ne.jp/kkatsuyoshi/20100111/1263220233

AppSales-Mobileの変更内容より...
http://github.com/omz/AppSales-Mobile/commit/cbaa5a19834fea092a49841281c0ef5a3bcf4f76
"11.xx.xx"を"17.xx.xx"に変更すれば良さそうだったので変更したらうまく動きました。

require 'rubygems'
require 'mechanize'

####################
#itunes conncetアカウント
$id = 'foo'
$pass = 'bar'
####################
 
def login(agent)
  login_page = agent.get("https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa")
  login_form = login_page.forms[0]
  login_form['theAccountName'] = $id
  login_form['theAccountPW'] = $pass
  home = agent.submit(login_form)
end

def checkAndSave(filename, body)
  original = String.new filename
  i = 1
  while true do
    if(File.exist?(filename)) then
	  f = open filename
	  s = f.read
	  f.close
	  if(s == body) then
	    return
	  end
	  filename = "#{original}.#{i}"
	  i += 1
	else
      f = open(filename, "wb")
      f.write body
      f.close
	end
  end
end

def download(agent)
  sales_page = agent.get("https://itts.apple.com/cgi-bin/WebObjects/Piano.woa")
  sales_form = sales_page.forms[1]
  sales_form['17.9']='Summary'
  sales_form['17.11'] = 'Daily'
  sales_form['hiddenSubmitTypeName'] = 'ShowDropDown'
  
  download_page = agent.submit(sales_form)
  download_form = download_page.forms[1]
  download_form.field_with(:name => '17.13.1').options.each do |option|
    download_form['17.9']='Summary'
    download_form['17.11'] = 'Daily'
    download_form['17.13.1'] = option.value
    download_form['hiddenSubmitTypeName'] = 'Download'
    download_form['download'] = 'Download'
	filename = "#{option.text.gsub('/', '_').downcase}.txt"
	body = agent.submit(download_form).body
	checkAndSave(filename, body)
  end
  
  sales_page = agent.get("https://itts.apple.com/cgi-bin/WebObjects/Piano.woa")
  sales_form = sales_page.forms[1]
  sales_form['17.9']='Summary'
  sales_form['17.11'] = 'Weekly'
  sales_form['hiddenSubmitTypeName'] = 'ShowDropDown'
  
  download_page = agent.submit(sales_form)
  download_form = download_page.forms[1]
  download_form.field_with(:name => '17.15.1').options.each do |option|
    download_form['17.9']='Summary'
    download_form['17.11'] = 'Weekly'
    download_form['17.15.1'] = option.value
    download_form['hiddenSubmitTypeName'] = 'Download'
    download_form['download'] = 'Download'
	filename = "#{option.text.gsub('/', '_').downcase}.txt"
	body = agent.submit(download_form).body
	checkAndSave(filename, body)
  end
end

agent = WWW::Mechanize.new

login agent
download agent