-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
51 lines (40 loc) · 1.21 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
49
50
51
"""
Flask application that serves as the API
"""
#!/usr/bin/env python
import logging
import json
from flask import Flask
from flask import render_template
from core.analyzer import run as analyze
from core.optimizer import run as optimize
# import argparse
app = Flask(__name__, static_url_path="", static_folder="static")
@app.route("/")
def template():
"""
Returns base template
"""
return render_template("index.html")
@app.route("/recommend_stocks/", methods=["GET"])
def recommend_stocks():
"""
Recommends stocks
"""
pre_selected_stocks = analyze()
print(pre_selected_stocks)
optimized_stocks = optimize(pre_selected_stocks, value=400)
return json.dumps(optimized_stocks)
@app.errorhandler(500)
def server_error(error):
"""
Log the error and stacktrace.
"""
logging.exception("An error occurred during a request: %s", error)
return "An internal error occurred.", 500
if __name__ == "__main__":
# parser = argparse.ArgumentParser()
# parser.add_argument("--budget", type=int)
# args = parser.parse_args()
# app.config["budget"] = args.budget
app.run(host="0.0.0.0", port=5000, debug=True)