Python list indices integers or slices

拈花ヽ惹草 提交于 2020-06-29 04:28:06

问题


I know there is a thread about this, I read it through multiple times and tried what was answered but it did not work for me. Now my Python code looks like this:

import requests
from flask import Flask, render_template, url_for

product_names = [list of products, removed it as it makes thread longer, I have these here just to see what products there are]

app = Flask(__name__)


@app.route('/')
def price():
    f = requests.get(
        "https://api.hypixel.net/skyblock/bazaar?key=[supposed to be secret]").json()
    products = [
        {
            "id": product["product_id"],
            "sell_price": product["sell_summary"]["pricePerUnit"],
            "buy_price": product["buy_summary"]["pricePerUnit"],
            "sell_volume": product["quick_status"]["sellVolume"],
            "buy_volume": product["quick_status"]["buyVolume"],
            "buy_orders": product["quick_status"]["buyOrders"],
            "sell_orders": product["quick_status"]["sellOrders"]
        }
        for product in f["products"].values()
    ]
    return render_template("index.html", products=products)


if __name__ == "__main__":
    app.run(debug=True)

Now the problem comes from "["sell_summary"]["pricePerUnit"]", and I tried to do [0] and [:] In between sellsummary and priceperunit, I think it doesn't work as I am in an array?

I am doing this in Flask, using Jinja

来源:https://stackoverflow.com/questions/61941491/python-list-indices-integers-or-slices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!