Spaces:
Sleeping

File size: 1,074 Bytes
abc5564
 
 
6622c8f
 
 
 
abc5564
 
 
6622c8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b10eca
 
 
 
 
 
 
abc5564
 
6622c8f
abc5564
 
6622c8f
 
 
9dcbf45
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
from flask import Flask, jsonify
from price_fetcher import fetch_price
from trend_engine import detect_trend
from aws_logger import upload_to_s3
import threading
import time
from datetime import datetime

app = Flask(__name__)

latest_signal = {"price": 0.0, "trend": "⏳ Waiting..."}

def background_refresh():
    global latest_signal
    while True:
        price = fetch_price()
        trend = detect_trend(price)
        latest_signal = {
            "price": round(price, 4),
            "trend": trend,
            "timestamp": datetime.utcnow().isoformat()
        }
        upload_to_s3(latest_signal)
        time.sleep(60)

@app.route("/", methods=["GET"])
def home():
    return jsonify({
        "message": "✅ Legion AI is running. Use /status for trend data.",
        "endpoints": ["/status"]
    })

@app.route("/status", methods=["GET"])
def status():
    return jsonify(latest_signal)

if __name__ == "__main__":
    thread = threading.Thread(target=background_refresh)
    thread.daemon = True
    thread.start()
    app.run(host="0.0.0.0", port=7860)