import fs from 'fs';
import fetch from 'node-fetch';

const instanceTypes = [
    "C5", "C5a", "C5ad", "C5d", "C5n", "C6a", "C6g", "C6gd", "C6gn", "C6i", "C6id", "C6in", "C7a", "C7g", "C7gd", "C7gn", "C7i", "C7i-flex", "C8g", "C8gd",
    "M5", "M5a", "M5ad", "M5d", "M5dn", "M5n", "M5zn", "M6a", "M6g", "M6gd", "M6i", "M6id", "M6idn", "M6in", "M7a", "M7g", "M7gd", "M7i", "M7i-flex", "M8g", "M8gd", "Mac1", "Mac2", "Mac2-m1ultra", "Mac2-m2", "Mac2-m2pro", "T2", "T3", "T3a", "T4g"
];

let dataset = []

for (const instanceType of instanceTypes) {
    console.log(`Fetching data for instance type: ${instanceType}`);
    const url = `https://ec2-pricing.runs-on.com/instances/${instanceType.toLowerCase()}`;
    const response = await fetch(url);
    const data = await response.json();
    dataset = dataset.concat(data.results);
}

fs.writeFileSync('dataset.json', JSON.stringify(dataset, null, 2), 'utf-8');