Created
May 2, 2011 20:34
-
-
Save levity/952307 to your computer and use it in GitHub Desktop.
scrape your historical monthly data usage (in KB) from att.com
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
#!/usr/bin/ruby | |
LOGIN, PASSWORD = 'your_number', 'your_password' | |
require 'rubygems' | |
require 'mechanize' | |
agent = Mechanize.new | |
agent.get 'https://wireless.att.com' | |
login = agent.page.forms_with(:name=>'loginActionForm').first | |
login.wireless_num = LOGIN | |
login.pass = PASSWORD | |
login.submit | |
puts 'logged in' | |
agent.get 'https://www.att.com/view/statementHistoryReflectionAction.doview?reportActionEvent=A_PMT_VIEW_ALL_AVAIL_STATE_HIST_LINK' | |
statements = agent.page.root.css('table.tableGen td a').map{|l| l['href'] } | |
puts "statement urls:\n#{statements.join("\n")}" | |
statements.each do |statement| | |
date = statement.match(/stmtID=(\d+)\|/)[1] | |
puts "loading info for #{date}..." | |
agent.get statement | |
agent.get 'https://www.att.com/pmt/jsp/mypayment/viewbill/viewFullBill.jsp' | |
data_usage = agent.page.at('td[text()*="DATA ACCESS"]').parent.css('td')[2].text | |
puts "usage: #{data_usage}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment