Skip to content

Instantly share code, notes, and snippets.

@harupong
Last active December 23, 2015 23:39
Show Gist options
  • Save harupong/6711830 to your computer and use it in GitHub Desktop.
Save harupong/6711830 to your computer and use it in GitHub Desktop.
My SoftBank fetcher for Ruby

My SoftBank fetcher

This script fetchs and returns following data from My SoftBank(マイソフトバンク).

  • network usage
  • more to come, maybe? (bills, points, etc)

You must create/have the account for My SoftBank to use it.

How to use

Set up environment variables:

  • SB_TELNUM: ID, which is a mobile number for My SoftBank.
  • SB_PASSWORD: password for above ID for My SoftBank.

Run ruby mysb.rb and the data gets returned. Right now, the result looks like (sorry, it's in Japanese only):

"今月のパケット残量 -> 48,827,582 パケット(5.83GB)"

Or, instead of setting up environment variables, you can pass them by running

SB_TELNUM=<your-mobile-number> SB_PASSWORD=<your-password> ruby mysb.rb

Requirements

Recommended to install the following.

  • Ruby 1.9
  • Mechanize

Special Thanks

MySoftBankのWeb明細をダウンロードする - xykの日記

Author

Haruo Nakayama

# coding: utf-8
require 'mechanize'
class MySBClient
def initialize
@agent = Mechanize.new
end
def usage_bill
login()
usage_page()
p "今月のパケット残量 -> " + allowance()
logout()
end
def allowance
@agent.page.search('table.contract-info.mt_20').search('tr.first').search('td')[-2].text.strip
end
def top
@agent.get('https://my.softbank.jp/msb/d/top')
end
def login
top()
@agent.page.forms[0].click_button
f = @agent.page.forms[0]
f.telnum = ENV["SB_TELNUM"]
f.password = ENV["SB_PASSWORD"]
f.submit
end
def usage_page
top()
@agent.page.link_with(:href=>/MRERE0000/).click
@agent.page.forms[0].submit
end
def logout
top()
@agent.page.link_with(:href=>/doLogout/).click
end
end
client = MySBClient.new
client.usage_bill()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment