File size: 1,620 Bytes
01c71d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastapi import APIRouter, HTTPException, Depends
from typing import Dict, Any

# Import the brain functions we just created
from core.thunderbird_engine import get_external_trends, predict_niche_trends

# FastAPI router for all Thunderbird-related endpoints
router = APIRouter(
    prefix="/thunderbird", # All routes in this file will start with /thunderbird
    tags=["Thunderbird - Market Intelligence"], # For Swagger UI documentation
)

# --- ENDPOINTS ---

@router.post("/get_pulse_data")
async def get_pulse_data() -> Dict[str, Any]:
    """
    This is the main endpoint for the /pulse page.
    It calls all necessary engine functions and combines their data into a single response.
    """
    print("πŸš€ API HIT: /thunderbird/get_pulse_data")
    try:
        # Call our core logic functions
        live_trends = get_external_trends()
        niche_predictions = predict_niche_trends()
        # In the future, we'll add the AI briefing call here as well

        # Combine all results into a single, clean JSON object for the frontend
        combined_data = {
            **live_trends,
            **niche_predictions,
            # "ai_briefing": ai_briefing_result (for later)
        }
        
        print("βœ… API SUCCESS: /thunderbird/get_pulse_data")
        return combined_data

    except Exception as e:
        print(f"❌ API ERROR in /get_pulse_data: {e}")
        # In case of an error, send a structured error message to the frontend
        raise HTTPException(
            status_code=500,
            detail=f"An internal error occurred in the Thunderbird engine: {e}"
        )