问题
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