Skip to content

Instantly share code, notes, and snippets.

@01infinity
Created July 14, 2013 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 01infinity/5993641 to your computer and use it in GitHub Desktop.
Save 01infinity/5993641 to your computer and use it in GitHub Desktop.
Need to pull out all EC2 properties from AWS management console? This script can help, will dump a csv, really usefull as a jumpstart for inventory/documentation Instructions: * Navigate the region you want to extract, e.g. https://console.aws.amazon.com/ec2/v2/home?region=eu-west-1 * Launch script in console (or maybe create a scriptlet?) credi…
var jquerySelector = "#instances_datatable_hook > div:nth-child(3) "
var columns = $(jquerySelector + 'thead th').map(function() {
return $(this).text();
});
var tableObject = $(jquerySelector + 'tbody tr').map(function(i) {
var row = {};
$(this).find('td').each(function(i) {
row[columns[i]] = $(this).text();
});
return row;
}).get();
console.log(columns);
console.log(tableObject);
window.open("data:text/csv;charset=utf-8," + escape(JSON2CSV(columns, tableObject)))
function JSON2CSV(columns, array) {
var str = '';
var line = '';
for (var index in columns[0]) {
var value = index + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
str = line + '\r\n';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
var value = array[i][index] + "";
line += '"' + value.replace(/"/g, '""') + '",';
}
line = line.slice(0, -1);
str += line + '\r\n';
}
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment