#!/bin/env zx
import fs from "fs"
import { exit } from "process";

const targetNumberOfCores = 28


const regions = JSON.parse(await $`aws ec2 describe-regions`).Regions.map(r => r.RegionName);

console.log("Available regions:", regions);

let pricings = []

for (const region of regions) {
    console.log("Fetching spot pricing data for region", region)
    const pricing = JSON.parse(await $`aws ec2 describe-spot-price-history --start-time ${new Date().toISOString()} --end-time ${new Date().toISOString()} --product-descriptions=Linux/UNIX --region ${region}`).SpotPriceHistory
    pricings = pricings.concat(pricing)
}

console.log("Spot pricing data:", pricings)
fs.writeFileSync("spot-pricing.json", JSON.stringify(pricings, null, 2), "utf-8")
