add marketing intelligence db

This commit is contained in:
jaehwang committed 2026-02-11 05:21:00 +00:00
1 parent e19c8c9d62
commit 54e66e4682
6 files changed
+256 -11

No files matched your search

+21 -7
View File
@@ -11,7 +11,7 @@ from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.ext.asyncio import AsyncSession
from app.database.session import get_session, AsyncSessionLocal
from app.home.models import Image
from app.home.models import Image, MarketingIntel
from app.user.dependencies.auth import get_current_user
from app.user.models import User
from app.home.schemas.home_schema import (
@@ -153,8 +153,10 @@ def _extract_region_from_address(road_address: str | None) -> str:
},
tags=["Crawling"],
)
async def crawling(request_body: CrawlingRequest):
return await _crawling_logic(request_body.url)
async def crawling(
request_body: CrawlingRequest,
session: AsyncSession = Depends(get_session)):
return await _crawling_logic(request_body.url, session)
@router.post(
"/autocomplete",
@@ -187,11 +189,15 @@ async def crawling(request_body: CrawlingRequest):
},
tags=["Crawling"],
)
async def autocomplete_crawling(request_body: AutoCompleteRequest):
url = await _autocomplete_logic(request_body.dict())
return await _crawling_logic(url)
async def autocomplete_crawling(
request_body: AutoCompleteRequest,
session: AsyncSession = Depends(get_session)):
url = await _autocomplete_logic(request_body.model_dump())
return await _crawling_logic(url, session)
async def _crawling_logic(url:str):
async def _crawling_logic(
url:str,
session: AsyncSession):
request_start = time.perf_counter()
logger.info("[crawling] ========== START ==========")
logger.info(f"[crawling] URL: {url[:80]}...")
@@ -280,7 +286,15 @@ async def _crawling_logic(url:str):
step3_3_start = time.perf_counter()
structured_report = await chatgpt_service.generate_structured_output(
marketing_prompt, input_marketing_data
)
marketing_intelligence = MarketingIntel(
place_id = scraper.place_id,
intel_result = structured_report.model_dump()
)
session.add(marketing_intelligence)
await session.commit()
await session.refresh(marketing_intelligence)
logger.debug(f"[MarketingPrompt] INSERT placeid {marketing_intelligence.place_id}")
step3_3_elapsed = (time.perf_counter() - step3_3_start) * 1000
logger.info(
f"[crawling] Step 3-3: GPT API 호출 완료 - ({step3_3_elapsed:.1f}ms)"