-
-
Save gabesmed/2563852 to your computer and use it in GitHub Desktop.
scrape your calls and texts history 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_phone_number', 'your_password' | |
require 'rubygems' | |
require 'mechanize' | |
agent = Mechanize.new | |
FileUtils.rm_rf('results/') | |
FileUtils.mkdir('results') | |
DEF_ARGS = { | |
:ajaxSupported => "", | |
:cancelURL => "https://www.att.com/olam/loginAction.olamexecute?goto=welcome", | |
:ck_userId => "", | |
:ck_userType => "", | |
:combinedBillAccountType => "", | |
:customerType => "", | |
:domain => ".att.com", | |
:flow_ind => "LGN", | |
:isPassThroughURL => "false", | |
:isPromoGraphicValid => "false", | |
:isSlidLogin => "true", | |
:isTarget => "false", | |
:ispLoginType => "false", | |
:localeInRequest => "", | |
:loginType => "SLID", | |
:pass => "", | |
:remember_me => "N", | |
:reportActionEvent => "A_LGN_LOGIN_SUB", | |
:rootPath => "/olam/English", | |
:source => "MYATT", | |
:style => "account", | |
:tGuardOn => "true", | |
:urlParameters => "goto=welcome&reportActionEvent=A_LGN_LOGIN_SUB", | |
:vhname => "www.att.com", | |
:wireLineOn => "true", | |
:wireless_num => "", | |
:wirelineLoginUrl => " https://cprodmasx.att.com/commonLogin/igate_wam/multiLogin.do?", | |
:x => 37, | |
:y => 13 | |
} | |
# Log in | |
agent.post('https://myattbx05.att.com/commonLogin/igate_wam/multiLogin.do', | |
DEF_ARGS.merge({:password => PASSWORD, :userid => LOGIN})) | |
# Save account name | |
name = agent.page.root.css('#dbUserName h3').text.gsub(/\w+/) { |word| | |
word.capitalize } | |
puts "Logged in: #{name}" | |
# Get statement | |
agent.get 'https://www.att.com/view/statementHistoryReflectionAction.doview?reportActionEvent=A_PMT_VIEW_ALL_AVAIL_STATE_HIST_LINK' | |
# Output statements | |
statements = agent.page.root.css('table.table td a').map{|l| l['href'] } | |
statements = statements.map{|s| "https://www.att.com#{s}"} | |
puts "#{statements.length} statements found." | |
File.open('results/statements.txt', 'w').write(statements.join("\n")) | |
# Loop through statements. | |
statements.each_with_index do |statement, i| | |
date = statement.match(/stmtID=(\d+)\|/)[1] | |
puts "Loading statement #{statement}" | |
# Get abbreviated statement | |
agent.get statement | |
# agent.page.save_as("results/statement#{i}.html") | |
# Get summary statement | |
data_usage = agent.page.at('td[text()*="DATA ACCESS"]').parent.css('td')[1].text | |
puts "- Usage: #{data_usage}" | |
if statement.include? "T01" then | |
puts "-> is current; skipping full." | |
next | |
end | |
# Get full statement | |
agent.get( | |
'https://www.att.com/pmt/jsp/mypayment/viewbill/viewFullBill.jsp', { | |
}) | |
# agent.page.save_as("results/statement#{i}_full.html") | |
# Get calls | |
call_table = agent.page.at('td h2[text()*="Call Detail"]').parent.parent.parent | |
call_file = File.open("results/calls#{i}.txt", 'w') | |
call_file.write("Date, Time, Number, Direction, Length\n") | |
num_calls = 0 | |
call_table.css('tr.rowclr').each do |row| | |
date = row.css('td')[2].text.strip | |
time = row.css('td')[3].text.strip | |
num = row.css('td')[5].text.strip | |
dir = row.css('td')[6].text.include?("INCOMING") ? "in" : "out" | |
length = row.css('td')[7].text.strip.to_i | |
call_file.write("#{date}, #{time.rjust(7)}, #{num}, #{dir.rjust(3)}, #{length}\n") | |
num_calls += 1 | |
end | |
call_file.close | |
puts "- #{num_calls} calls." | |
# Get texts | |
data_table = agent.page.at('td h2[text()*="Data Detail"]').parent.parent.parent | |
data_file = File.open("results/texts#{i}.txt", 'w') | |
data_file.write("Date, Time, Number, Direction\n") | |
num_texts = 0 | |
data_table.css('tr.rowclr').each do |row| | |
type = row.css('td')[5].css('nobr').text | |
if not type.downcase.include? "text" then next end | |
date = row.css('td')[2].text.strip | |
time = row.css('td')[3].text.strip | |
num = row.css('td')[4].text.strip | |
dir = row.css('td')[10].css('nobr').text.downcase.include?("in") ? "in" : "out" | |
data_file.write("#{date}, #{time.rjust(7)}, #{num.rjust(3)}, #{dir}\n") | |
num_texts += 1 | |
end | |
data_file.close | |
puts "- #{num_texts} texts." | |
# break | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment