Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jupyter-naas
GitHub Repository: jupyter-naas/awesome-notebooks
Path: blob/master/Cloud Mercato/Cloud_Mercato_Compare_VM_pricing.ipynb
2973 views
Kernel: Python 3

Cloud Mercato.png

Cloud Mercato - Compare VM pricing

Give Feedback | Bug report

Tags: #cloud #infrastruture #pricing #vm #iaas #analytics #compute

Last update: 2023-04-12 (Created: 2022-11-01)

Description: Cloud Mercato is an online platform that allows users to compare virtual machine pricing from different cloud providers.

Input

Import libraries

import requests import pandas as pd import naas

Setup Variables

  • Create your token

  • You can access data without a token but you are limited to 3 requests/days

  • Get a paid account to have access to VM with +16 CPUs

# Input CPU = 4 # in CPU number RAM = 2 # in GB # Anonymous users are limited TOKEN = None # Output csv_output = "cloud-mercato-vm-pricing.csv"

Model

Declare constants

COLUMN_PARAMS = { "table-col-provider": "on", "table-col-name": "on", "table-col-cpu_number": "on", "table-col-ram": "on", "table-col-hourly": "on", "table-col-monthly": "on", "table-col-yearly1_noupfront": "on", "table-col-yearly1_parupfront": "on", "table-col-yearly1_parupfront_fee": "on", "table-col-yearly1_allupfront_fee": "on", "table-col-yearly2_noupfront": "on", "table-col-yearly2_parupfront": "on", "table-col-yearly2_parupfront_fee": "on", "table-col-yearly2_allupfront_fee": "on", "table-col-yearly3_noupfront": "on", "table-col-yearly3_parupfront": "on", "table-col-yearly3_parupfront_fee": "on", "table-col-yearly3_allupfront_fee": "on", "table-col-currency": "on", "table-col-rate": "on", }
FILTER_PARAMS = { "cpu_number_min": CPU, "cpu_number_max": CPU, "ram_min": RAM - 1, "ram_max": RAM + 1, "currency-currency": "USD", }

Get data using request

params = {} params.update(COLUMN_PARAMS) params.update(FILTER_PARAMS) headers = {} if TOKEN: headers["Authorization"] = "Token %s" % TOKEN response = requests.get( "https://p2p.cloud-mercato.com/flavors/csv", params=params, headers=headers, stream=True, ) if response.status_code == 429: raise Exception("Download is limited for free users. Please wait or subscribe.") df = pd.read_csv(response.raw) print("Shape: ", df.shape) df

Output

Save result in csv

df.to_csv(csv_output, index=False)

Share csv output with naas

naas.asset.add(csv_output) # -> Uncomment the line below to remove your asset # naas.asset.delete()