Defoc

Untitled

Dec 3rd, 2021
828
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from flask import Flask, render_template
  2. import requests
  3.  
  4. app = Flask(__name__)
  5. API_URL = "https://financialmodelingprep.com/api/v3/stock/real-time-price/{TICKER}"
  6.  
  7.  
  8. @app.route('/<ticker>')
  9. def ticker_show(ticker):
  10.     price = get_price(ticker=ticker)
  11.     return render_template("stock_quote.html", ticker=ticker.upper(),stock_price=price)
  12.  
  13.  
  14. def get_price(ticker):
  15.     data = requests.get(API_URL.format(ticker=ticker.upper()),
  16.                         params={"apikey": "a11094f84f3ad7ba97ffb1ff"}).json()
  17.     return data["price"]
  18.  
  19. @app.route("/")
  20. def index():
  21.     return render_template("index.html")
RAW Paste Data