Commit ·
51fe39a
1
Parent(s): 0a7e81a
Fix circular import in trends module - create TrendsClient directly in router
Browse files- modules/trends/__init__.py +4 -11
- modules/trends/router.py +4 -1
modules/trends/__init__.py
CHANGED
|
@@ -3,25 +3,15 @@ Trends Module - Google Trends Analysis
|
|
| 3 |
Uses pytrends for trend data analysis
|
| 4 |
"""
|
| 5 |
import logging
|
| 6 |
-
from fastapi import APIRouter
|
| 7 |
from config import NCAkitConfig
|
| 8 |
|
| 9 |
-
from .router import router
|
| 10 |
-
from .services.trends_client import TrendsClient
|
| 11 |
-
|
| 12 |
logger = logging.getLogger(__name__)
|
| 13 |
|
| 14 |
-
# Module will be initialized during registration
|
| 15 |
-
trends_client = None
|
| 16 |
-
|
| 17 |
|
| 18 |
def register(app, config: NCAkitConfig):
|
| 19 |
"""Register trends module with the app"""
|
| 20 |
-
global trends_client
|
| 21 |
-
|
| 22 |
try:
|
| 23 |
-
|
| 24 |
-
trends_client = TrendsClient()
|
| 25 |
|
| 26 |
# Include router
|
| 27 |
app.include_router(router, prefix="/api/trends", tags=["Trends"])
|
|
@@ -31,4 +21,7 @@ def register(app, config: NCAkitConfig):
|
|
| 31 |
|
| 32 |
except Exception as e:
|
| 33 |
logger.error(f"Failed to register trends module: {e}")
|
|
|
|
|
|
|
| 34 |
return False
|
|
|
|
|
|
| 3 |
Uses pytrends for trend data analysis
|
| 4 |
"""
|
| 5 |
import logging
|
|
|
|
| 6 |
from config import NCAkitConfig
|
| 7 |
|
|
|
|
|
|
|
|
|
|
| 8 |
logger = logging.getLogger(__name__)
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def register(app, config: NCAkitConfig):
|
| 12 |
"""Register trends module with the app"""
|
|
|
|
|
|
|
| 13 |
try:
|
| 14 |
+
from .router import router
|
|
|
|
| 15 |
|
| 16 |
# Include router
|
| 17 |
app.include_router(router, prefix="/api/trends", tags=["Trends"])
|
|
|
|
| 21 |
|
| 22 |
except Exception as e:
|
| 23 |
logger.error(f"Failed to register trends module: {e}")
|
| 24 |
+
import traceback
|
| 25 |
+
logger.error(traceback.format_exc())
|
| 26 |
return False
|
| 27 |
+
|
modules/trends/router.py
CHANGED
|
@@ -13,12 +13,15 @@ from .schemas import (
|
|
| 13 |
YouTubeTrendsRequest,
|
| 14 |
TrendingTopic
|
| 15 |
)
|
| 16 |
-
from . import
|
| 17 |
|
| 18 |
logger = logging.getLogger(__name__)
|
| 19 |
|
| 20 |
router = APIRouter()
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
@router.post("/trending-now",
|
| 24 |
response_model=TrendingNowResponse,
|
|
|
|
| 13 |
YouTubeTrendsRequest,
|
| 14 |
TrendingTopic
|
| 15 |
)
|
| 16 |
+
from .services.trends_client import TrendsClient
|
| 17 |
|
| 18 |
logger = logging.getLogger(__name__)
|
| 19 |
|
| 20 |
router = APIRouter()
|
| 21 |
|
| 22 |
+
# Create client instance
|
| 23 |
+
trends_client = TrendsClient()
|
| 24 |
+
|
| 25 |
|
| 26 |
@router.post("/trending-now",
|
| 27 |
response_model=TrendingNowResponse,
|