Created
February 21, 2019 08:51
-
-
Save housemeow/6011e19102849a84d9dceadde50c6083 to your computer and use it in GitHub Desktop.
Find Cheapest EC2 Instance
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
// https://aws.amazon.com/tw/ec2/pricing/on-demand/ | |
var $item = $('.button.lb-dropdown-label:eq(0) li:eq(0)'), | |
clicked = false, | |
regions = []; | |
var interval = setInterval(function() { | |
if ($item.length == 0) { | |
clearInterval(interval); | |
console.log('Cheapest', regions.reduce((a, b) => b.price < a.price ? b : a, { price: 1000})); | |
} | |
if (!clicked) { | |
$item.click().click(); | |
clicked = true; | |
} | |
var region = $item.data('region'); | |
if ($('.aws-plc-content:eq(0)').find(`div[data-region=${region}] table`).length > 0) { | |
var row = $.map($(`[data-region="${region}"] tr td:nth-child(6)`), el => ({ price: $(el).text(), ec2: $(el).siblings(':first').text() })) | |
.map(row => ({ price: row.price.match(/每小時 (\d*\.\d*) USD/)[1], ec2: row.ec2 })) | |
.map(row => ({ price: parseFloat(row.price), ec2: row.ec2 })) | |
.reduce((a, b) => b.price < a.price ? b : a, { price: 1000 }), | |
name = $(`li[data-region="${region}"]:eq(0)`).text(); | |
regions.push({ | |
region, | |
name, | |
price: row.price, | |
ec2: row.ec2, | |
}); | |
$item = $item.next(); | |
clicked = false; | |
} | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment