Spaces:
Sleeping

legion-ai / app.py
Loading404's picture
Update app.py
6622c8f verified
Raw History Blame Contribute Delete
1.07 kB
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)