Skip to content

Instantly share code, notes, and snippets.

@levity
Created May 2, 2011 20:34
Show Gist options
  • Save levity/952307 to your computer and use it in GitHub Desktop.
Save levity/952307 to your computer and use it in GitHub Desktop.
scrape your historical monthly data usage (in KB) from att.com
#!/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