简体   繁体   English

如何使用python通过AWS定价API过滤json?

[英]How can I use python to filter the json with AWS list pricing API?

I want to filter the json that operatinSystem are linux ,and I have some problem with it,the part of json in 我想过滤OperatinSystem是linux的json,但我有一些问题,json中的部分

 '' : { 

that I don't know how dictionary represent it and 我不知道字典是怎么表示的,

"DQ578CGN99KG6ECF" : { 

how can I represent it with wildcard, anyone could help my please. 我怎么用通配符表示它,任何人都可以帮助我。

import json
import urllib2
response=urllib2.urlopen('https://pricing.us-east-1.amazonaws.com/offers/v1.0/aws/AmazonEC2/current/index.json')
url=response.read()
urlj=json.loads(url)
filterx=[x for x in urlj if x['??']['??']["attributes"]["operatingSystem"] == 'linux']

I'm not sure about the wildcard representation. 我不确定通配符表示形式。 I'll look into it and get back to you. 我会调查一下,然后再回覆您。 Meanwhile, I have already worked with this json before so I can tell you how to access the information you need. 同时,我之前已经使用过此json,所以我可以告诉您如何访问所需的信息。 The information you need can be obtained as follows: 您可以通过以下方式获取所需信息:

for each_product in urlx['products']:
    if urlx['products'][each_product]['attributes']['operatingSystem']=="linux":
        #your code here

If you need pricing information from the json you need to take the product code string and look into the priceDimensions field for it. 如果您需要json中的价格信息,则需要获取产品代码字符串,并查看priceDimensions字段。 Look at the sample json and code accordingly. 查看示例json并相应地进行编码。 https://aws.amazon.com/blogs/aws/new-aws-price-list-api/ https://aws.amazon.com/blogs/aws/new-aws-price-list-api/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM