如何使用烧瓶从 yahoo finance API 获取所需的数据格式,这让我很困惑

how to get a required data format from yahoo finance API using flask, it is confusing me

我需要这个数据(NIO Inc. NIO 21.05 -0.29257 77123545 68510787 99146121216 ) 作为我的 Flask Web 应用程序的输出,格式为 Json。

我期望的输出图像是 link - also required data's are in yellow boxed

(或)

你可以指导我如何将下面提到的这些输出作为烧瓶网络 API 格式。另外,我可以继续下一步了。

import yfinance as yf
stocks = yf.Ticker("NIO")
a = stocks.info['shortName']
b = stocks.info['symbol']
c = stocks.info['currentPrice']
d = stocks.info['profitMargins']
e = stocks.info['volume']
f = stocks.info['averageVolume']
g = stocks.info['marketCap']
#h = stocks.info['trailingPE']
print(a, b, c, d, e, f, g)

Output - NIO Inc. NIO 21.05 -0.29257 77123545 68510787 99146121216

但是,我实际上得到了 json 格式的完整信息,需要任何指导。

app.py

# importing Flask and other modules
from flask import Flask, request, render_template
import yfinance as yf
# Flask constructor
app = Flask(__name__)

@app.route('/info/', methods =["GET", "POST"])
def display_quote():
    if request.method == "POST":
        # getting input text in HTML form
        text = request.form['text']
    
        symbol = request.args.get('symbol', text)

        quote = yf.Ticker(symbol)

        return quote.info
    return render_template("form.html")

if __name__=='__main__':
    app.run() 

templates/form.html

<form method="POST">
    <input name="text">
    <input type="submit">
</form>

你只需要用你想要的信息创建一个字典,return在烧瓶视图中

quote = yf.Ticker(symbol)
return {
   "a": quote.info['shortName'],
   "b": quote.info['symbol'],
   "c": quote.info['currentPrice'],
   "d": quote.info['profitMargins'],
   "e": quote.info['volume'],
   "f": quote.info['averageVolume'],
   "g": quote.info['marketCap'],
}

这会给你一个 json 烧瓶路线的回应