Skip to content

Instantly share code, notes, and snippets.

@AdamEsterle
Created June 1, 2015 12:53
Show Gist options
  • Save AdamEsterle/3bf42dc6ce1d6e110953 to your computer and use it in GitHub Desktop.
Save AdamEsterle/3bf42dc6ce1d6e110953 to your computer and use it in GitHub Desktop.
var ATTExcel = function() {
var usage = {};
var dollars = {};
var rollOverData = '';
var totalBill = '';
this.begin = function() {
if (getCache()) {
getUsage();
getBill();
} else {
alert("Not logged in?");
}
return true;
};
var 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;
};
var 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
});
};
var getBill = function() {
// Bill Details
jQuery.ajax({
url: 'https://www.att.com/olam/billOverviewTiles.myworld',
success: function(dollarData) {
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
*/
var combineDollarsAndData = function(dollars, usage) {
var combinedString = '';
for (var i in dollars) {
combinedString += dollars[i] + "\t" + usage[i] + "\n";
};
return combinedString;
};
var displayData = function(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