-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
68 lines (55 loc) · 1.6 KB
/
Copy pathapp.py
File metadata and controls
68 lines (55 loc) · 1.6 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from flask import Flask, render_template, jsonify
from apscheduler.schedulers.background import BackgroundScheduler
from analysis import analyze_all_stocks
from notifications import notify_analysis_done
from config import SCHEDULE_HOUR, SCHEDULE_MINUTE
from notifications import notify_analysis_done
app = Flask(__name__)
LATEST_RESULTS = []
# SCHEDULED JOB
def run_daily_analysis():
global LATEST_RESULTS
results, _ = analyze_all_stocks()
LATEST_RESULTS = results
notify_analysis_done(results)
# ROUTES
@app.route("/")
def index():
return render_template("index.html")
@app.route("/analyze", methods=["POST"])
def analyze():
global LATEST_RESULTS
results, _ = analyze_all_stocks()
LATEST_RESULTS = results
return jsonify({
"top_positive": results[0] if len(results) > 0 else {},
"top_negative": results[1] if len(results) > 1 else {}
})
@app.route("/last-results")
def last_results():
return jsonify(LATEST_RESULTS)
@app.route("/analyze-all", methods=["POST"])
def analyze_all():
from analysis import analyze_all_csv_stocks
results = analyze_all_csv_stocks()
if not results:
return jsonify({
"status": "empty",
"message": "No valid stocks found"
})
notify_analysis_done(results)
return jsonify({
"status": "ok",
"data": results
})
# APP START
if __name__ == "__main__":
scheduler = BackgroundScheduler()
scheduler.add_job(
run_daily_analysis,
"cron",
hour=SCHEDULE_HOUR,
minute=SCHEDULE_MINUTE
)
scheduler.start()
app.run(debug=True)