reachify-ai-service / api /thunderbird_routes.py
amitbhatt6075's picture
feat(thunderbird): Add market intelligence module with new model and APIs
01c71d2
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}"
)