Created
August 13, 2018 03:33
-
-
Save GeneralD/3ddd0b7b023be61d1424f52758cebfd4 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 'json' | |
# your my softbank login id and password | |
phone = "***********" | |
password = "********" | |
agent = Mechanize.new | |
agent.user_agent_alias = 'iPhone' | |
agent.follow_meta_refresh = true | |
agent.redirect_ok = true | |
agent.redirection_limit=10 | |
agent.get 'https://my.softbank.jp/msb/d/auth/doCasisLogin' do |page| | |
mypage = page.form_with id: 'authActionForm' do |form| | |
form.telnum = phone | |
form.password = password | |
end.submit | |
m = mypage.content.toutf8.match /cid=mysb_(.+?)_msb\// | |
id = m[1] | |
pageRedirect01 = agent.get 'https://my.softbank.jp/msb/d/webLink/doSend/MRERE0000?cid=mysb_' + id + '_msb/d/top_005_deta' | |
mfiv = "" | |
mfsb = "" | |
pageRedirect01.form_with name: 'webLink' do |form| | |
mfiv = form.mfiv | |
mfsb = form.mfsb | |
end | |
pageRedirect02 = agent.post 'https://re11.my.softbank.jp/resfe/top/', { | |
"mfiv" => mfiv, | |
"mfsb" => mfsb | |
} | |
dateRegex = pageRedirect02.content.toutf8.match /\t([0-9]{4}年[0-9]+月[0-9]+日)/ | |
dateCrop = dateRegex[1].strip | |
cY = dateCrop.split("年")[0].strip | |
cM = dateCrop.split("年")[1].split("月")[0] | |
cD = dateCrop.split("年")[1].split("月")[1].split("日")[0] | |
enddate = Date.new(cY.to_i, cM.to_i, cD.to_i) | |
maxRegex = pageRedirect02.content.toutf8.match /基本データ量<\/th><td>(\d+(?:\.\d+)?)GB<\/td>/ | |
maxCrop = maxRegex[1].strip | |
remainRegex = pageRedirect02.content.toutf8.match /残りデータ量<\/p><p><span class=[^>]+>(\d+(?:\.\d+)?)<\/span>/ | |
remainCrop = remainRegex[1].strip | |
puts [ | |
'end':enddate.strftime("%Y/%m/%d"), | |
'max':maxCrop, | |
'use':remainCrop, | |
].to_json | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment