forked from roh1th-s/stockify
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
48 lines (35 loc) · 1.54 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from flask import Flask, render_template, request
from stock_prediction import graph_current_prices, graph_predicted_prices, get_stock_data
from flask import Flask, render_template, request, redirect
app = Flask(__name__)
#serve website (base.html as base and index.html as template)
@app.route("/",methods=["POST", "GET"] )
def index():
return render_template("landing.html")
@app.route("/predict", methods=["POST", "GET"])
def home():
return render_template("predict.html")
@app.route("/result", methods=["POST", "GET"])
def result():
ticker_sym = request.args.get("ticker")
days = request.args.get("days")
if not ticker_sym or not days:
return redirect("/predict")
stock_data = get_stock_data(ticker_sym)
company_name = stock_data["shortName"]
market_cap = stock_data["marketCap"]
country = stock_data["country"]
volume = stock_data["volume"]
sector = stock_data["sector"]
industry = stock_data["industry"]
live_price_graph = graph_current_prices(ticker_sym, company_name)
predicted_price_graph = graph_predicted_prices(ticker_sym, days)
if not (live_price_graph and predicted_price_graph):
# error
return "Bad request", 400
return render_template("result.html", tickerSym=ticker_sym, companyName=company_name,
noDays=days, marketCap=market_cap, country=country,
volume=volume, sector=sector, industry=industry,
liveGraphJson=live_price_graph, predictedGraphJson=predicted_price_graph)
if __name__ == "__main__":
app.run(debug=True)