Commit 187c8958 by diegolima

Adicionar parser EC2 Aws

0 parents
Showing with 23 additions and 0 deletions
import urllib.request
import json
from pprint import pprint
TERM_ONDEMAND = 'JRTCKXETXF' #TODO: Find out where to get this from
HOURLY_DIMENSION = '6YS6EN2CT7' #TODO: Find out where to get this from
with urllib.request.urlopen("https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json") as url:
DATA = json.load(url)
for product in DATA["products"]:
if DATA['products'][product]['productFamily'] == 'Compute Instance':
sku = DATA['products'][product]['sku']
key = DATA['terms']['OnDemand'].get(sku)
if key:
cost = key[sku + '.' + TERM_ONDEMAND]['priceDimensions'][sku + '.' + TERM_ONDEMAND + '.' + HOURLY_DIMENSION]['pricePerUnit']['USD']
if cost != '0.0000000000':
print('aws', end=',')
print(DATA['products'][product]['attributes']['instanceType'], end=',')
print(DATA['products'][product]['attributes']['vcpu'], end=',')
print(DATA['products'][product]['attributes']['memory'], end=',')
print(cost, end=',')
print(DATA['products'][product]['attributes']['location'], end=',')
print(DATA['products'][product]['attributes']['operatingSystem'])
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!