Created
May 28, 2015 15:38
-
-
Save AdamEsterle/e008c1ddaf374ee70be0 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
var ATTExcel = function() { | |
usage = {}; | |
dollars = {}; | |
rollOverData = ''; | |
totalBill = ''; | |
this.begin = function() { | |
if (this.getCache()) { | |
this.getUsage(); | |
this.getBill(); | |
} else { | |
alert("Not logged in?"); | |
} | |
return true; | |
}; | |
this.getCache = function() { | |
var success = true; | |
jQuery.ajax({ | |
url: 'https://www.att.com/view/billSummary.do', | |
async: false, | |
error: function(home) { | |
success = false; | |
}, | |
success: function(home) { | |
if(home.indexOf("Login Pg") != -1){ | |
success = false; | |
} | |
} | |
}); | |
return success; | |
}; | |
this.getUsage = function() { | |
// Data Usage | |
jQuery.ajax({ | |
url: 'https://www.att.com/olam/billUsageTiles.myworld', | |
success: function(mbData) { | |
var names = []; | |
jQuery(mbData).find('p.font14.botMar0 > strong').each(function(i) { | |
names.push(jQuery(this).text().trim()); | |
}); | |
jQuery(mbData).find('a[title="Web Usage"]').each(function(i) { | |
usage[names[i]] = parseFloat(jQuery(this).find('span > strong').text().trim()) * 1024; | |
}); | |
rollOverData = parseFloat(jQuery(mbData).find('#wirelessRolloverBookPopup tbody > tr:eq(0) > td:eq(2) > strong').text().trim()) * 1024; | |
}, | |
async: false | |
}); | |
}; | |
this.getBill = function() { | |
// Bill Details | |
jQuery.ajax({ | |
url: 'https://www.att.com/olam/billOverviewTiles.myworld', | |
success: function(dollarData) { | |
var names = []; | |
jQuery(dollarData).find('a.MarRight10').each(function(i) { | |
var name = jQuery(this).text().trim(); | |
names.push(name.substring(0, name.length - 12).trim()); | |
}); | |
totalBill = jQuery(dollarData).find('span.billingOrangeText.font32.rel').text().trim(); | |
jQuery(dollarData).find('span.flipper.float-right.font14.top10px.padRight20.colorBlack').not('.ie7Top7').each(function(i) { | |
dollars[names[i]] = jQuery(this).text().trim(); | |
}); | |
var stringForGoogleSheets = ''; | |
stringForGoogleSheets += totalBill + '\n'; | |
stringForGoogleSheets += rollOverData + '\n'; | |
stringForGoogleSheets += combineDollarsAndData(dollars, usage); | |
displayData(stringForGoogleSheets); | |
}, | |
async: false | |
}); | |
}; | |
/* | |
* Expected format | |
* dollars["Adam"] = 65 | |
* data["Adam"] = 4500 | |
* Order will matter | |
* AT&T sorts a-z by phone number | |
*/ | |
function combineDollarsAndData(dollars, usage) { | |
var combinedString = ''; | |
for (var i in dollars) { | |
combinedString += dollars[i] + "\t" + usage[i] + "\n"; | |
}; | |
return combinedString; | |
} | |
function displayData(string) { | |
if (!jQuery('#excelCopy').length) { | |
jQuery('body').prepend('<textarea style="width:200px;height:200px;" id="excelCopy"></textarea>'); | |
} | |
jQuery('#excelCopy').val(string).focus().select(); | |
} | |
} | |
excelObj = new ATTExcel; | |
excelObj.begin(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment