Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
10 kB
3
Indexable
Never
import requests


def get_data(url, region_name):
    response = requests.get(url)
    data_info = response.json()

    if response.status_code == 200:
        instances = []
        region_data = data_info["regions"].get(region_name, {})

        for instance_name, instance_attributes in region_data.items():
            instance = {
                "Instance Name": instance_name,
                "Rate Code": instance_attributes.get("rateCode", ""),
                "Price": instance_attributes.get("price", ""),
                "Location": instance_attributes.get("Location", ""),
                "Instance Family": instance_attributes.get("Instance Family", ""),
                "vCPU": instance_attributes.get("vCPU", ""),
                "Memory": instance_attributes.get("Memory", ""),
                "Storage": instance_attributes.get("Storage", ""),
                "Network Performance": instance_attributes.get(
                    "Network Performance", ""
                ),
                "Operating System": instance_attributes.get("Operating System", ""),
                "Pre Installed S/W": instance_attributes.get("Pre Installed S/W", ""),
                "License Model": instance_attributes.get("License Model", ""),
            }
            instances.append(instance)

        return instances
    else:
        return None


def north_america():
    north_america_urls = [
        [
            "US East (N. Virginia)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/US%20East%20(N.%20Virginia)/Linux/index.json?timestamp=1695335197182",
        ],
        [
            "US East (N. California)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/US%20West%20(N.%20California)/Linux/index.json?timestamp=1695335943885",
        ],
        [
            "US West (Oregon)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/US%20West%20(Oregon)/Linux/index.json?timestamp=1695336005767",
        ],
        [
            "Canada (Central)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Canada%20(Central)/Linux/index.json?timestamp=1695336038545",
        ],
        [
            "AWS GovCloud (US-East)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/AWS%20GovCloud%20(US-East)/Linux/index.json?timestamp=1695336076977",
        ],
        [
            "AWS GovCloud (US-West)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/AWS%20GovCloud%20(US)/Linux/index.json?timestamp=1695336143250",
        ],
    ]

    north_america = []
    for region_info in north_america_urls:
        region = region_info[0]
        url = region_info[1]
        data = get_data(url, region)
        north_america.append(data)

    return north_america


def africa():
    africa_urls = [
        [
            "Africa (Cape Town)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Africa%20(Cape%20Town)/Linux/index.json?timestamp=1695336201165",
        ]
    ]

    africa = []
    for region_info in africa_urls:
        region = region_info[0]
        url = region_info[1]
        data = get_data(url, region)
        africa.append(data)

    return africa


def asia_pacific():
    asia_pacific = [
        [
            "Asia Pacific (Hong Kong)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Hong%20Kong)/Linux/index.json?timestamp=1695336236566",
        ],
        [
            "Asia Pacific (Hyderabad)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Hyderabad)/Linux/index.json?timestamp=1695336267211",
        ],
        [
            "Asia Pacific (Jakarta)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Jakarta)/Linux/index.json?timestamp=1695336335452",
        ],
        [
            "Asia Pacific (Melbourne)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Melbourne)/Linux/index.json?timestamp=1695336377353",
        ],
        [
            "Asia Pacific (Mumbai)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Mumbai)/Linux/index.json?timestamp=1695336414559",
        ],
        [
            "Asia Pacific (Osaka)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Osaka)/Linux/index.json?timestamp=1695336448367",
        ],
        [
            "Asia Pacific (Seoul)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Seoul)/Linux/index.json?timestamp=1695336489384",
        ],
        [
            "Asia Pacific (Singapore)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Asia%20Pacific%20(Singapore)/Linux/index.json?timestamp=1695336516652",
        ],
        [
            "Asia Pacific (Sydney)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Australia%20(Sydney)/Linux/index.json?timestamp=1695336549342",
        ],
        [
            "Asia Pacific (Tokyo)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Australia%20(Tokyo)/Linux/index.json?timestamp=1695336572681",
        ],
    ]

    asia_pacific = []
    for region_info in asia_pacific:
        region = region_info[0]
        url = region_info[1]
        data = get_data(url, region)
        asia_pacific.append(data)

    return asia_pacific


def europe():
    europe = [
        [
            "Europe (Frankfurt)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(Frankfurt)/Linux/index.json?timestamp=1695336606682",
        ],
        [
            "Europe (Ireland)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(Ireland)/Linux/index.json?timestamp=1695336640824",
        ],
        [
            "Europe (London)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(London)/Linux/index.json?timestamp=1695336671834",
        ],
        [
            "Europe (Milan)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(Milan)/Linux/index.json?timestamp=1695336709113",
        ],
        [
            "Europe (Paris)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(Paris)/Linux/index.json?timestamp=1695336734334",
        ],
        [
            "Europe (Spain)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(Spain)/Linux/index.json?timestamp=1695336756525",
        ],
        [
            "Europe (Stockholm)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(Stockholm)/Linux/index.json?timestamp=1695336795677",
        ],
        [
            "Europe (Zurich)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/EU%20(Zurich)/Linux/index.json?timestamp=1695336817871",
        ],
    ]

    europe = []
    for region_info in europe:
        region = region_info[0]
        url = region_info[1]
        data = get_data(url, region)
        europe.append(data)

    return europe


def middle_east():
    middle_east = [
        [
            "Middle East (Bahrain)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Middle%20East%20(Bahrain)/Linux/index.json?timestamp=1695336880976",
        ],
        [
            "Middle East (UAE)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/Middle%20East%20(UAE)/Linux/index.json?timestamp=1695336906621",
        ],
    ]

    middle_east = []
    for region_info in middle_east:
        region = region_info[0]
        url = region_info[1]
        data = get_data(url, region)
        middle_east.append(data)

    return middle_east


def south_america():
    south_america = [
        [
            "South America (Sao Paulo)",
            "https://b0.p.awsstatic.com/pricing/2.0/meteredUnitMaps/ec2/USD/current/ec2-ondemand-without-sec-sel/South%20America%20(Sao%20Paulo)/Linux/index.json?timestamp=1695336944637",
        ]
    ]

    south_america = []
    for region_info in south_america:
        region = region_info[0]
        url = region_info[1]
        data = get_data(url, region)
        south_america.append(data)

    return south_america


def main():
    # north_america_data = north_america()
    africa_data = africa()
    # asia_pacific_data = asia_pacific()
    # europe_data = europe()
    # middle_east_data = middle_east()
    # south_america_data = south_america()

    # print(north_america_data)
    print(africa_data)
    # print(asia_pacific_data)
    # print(europe_data)
    # print(middle_east_data)
    # print(south_america_data)


main()