크롤링에 마케팅 분석 추가, 태그 추가, 부대 시설 추가 완료
This commit is contained in:
1 parent
79ec5daa0d
commit
b5b8e88005
11 files changed
+237
-11
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import re
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
@@ -19,8 +20,10 @@ from app.home.schemas.home import (
|
||||
GenerateResponse,
|
||||
GenerateUploadResponse,
|
||||
GenerateUrlsRequest,
|
||||
MarketingAnalysis,
|
||||
ProcessedInfo,
|
||||
)
|
||||
from app.utils.chatgpt_prompt import ChatgptService
|
||||
from app.home.worker.main_task import task_process
|
||||
from app.utils.nvMapScraper import NvMapScraper
|
||||
|
||||
@@ -68,6 +71,32 @@ def _extract_region_from_address(road_address: str | None) -> str:
|
||||
return ""
|
||||
|
||||
|
||||
def _parse_marketing_analysis(raw_response: str) -> MarketingAnalysis:
|
||||
"""ChatGPT 마케팅 분석 응답을 파싱하여 MarketingAnalysis 객체로 변환"""
|
||||
tags: list[str] = []
|
||||
facilities: list[str] = []
|
||||
report = raw_response
|
||||
|
||||
# JSON 블록 추출 시도
|
||||
json_match = re.search(r"```json\s*(\{.*?\})\s*```", raw_response, re.DOTALL)
|
||||
if json_match:
|
||||
try:
|
||||
json_data = json.loads(json_match.group(1))
|
||||
tags = json_data.get("tags", [])
|
||||
facilities = json_data.get("facilities", [])
|
||||
# JSON 블록을 제외한 리포트 부분 추출
|
||||
report = raw_response[: json_match.start()].strip()
|
||||
# --- 구분자 제거
|
||||
if report.startswith("---"):
|
||||
report = report[3:].strip()
|
||||
if report.endswith("---"):
|
||||
report = report[:-3].strip()
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
|
||||
return MarketingAnalysis(report=report, tags=tags, facilities=facilities)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/crawling",
|
||||
summary="네이버 지도 크롤링",
|
||||
@@ -100,18 +129,34 @@ async def crawling(request_body: CrawlingRequest):
|
||||
|
||||
# 가공된 정보 생성
|
||||
processed_info = None
|
||||
marketing_analysis = None
|
||||
|
||||
if scraper.base_info:
|
||||
road_address = scraper.base_info.get("roadAddress", "")
|
||||
customer_name = scraper.base_info.get("name", "")
|
||||
region = _extract_region_from_address(road_address)
|
||||
|
||||
processed_info = ProcessedInfo(
|
||||
customer_name=scraper.base_info.get("name", ""),
|
||||
region=_extract_region_from_address(road_address),
|
||||
customer_name=customer_name,
|
||||
region=region,
|
||||
detail_region_info=road_address or "",
|
||||
)
|
||||
|
||||
# ChatGPT를 이용한 마케팅 분석
|
||||
chatgpt_service = ChatgptService(
|
||||
customer_name=customer_name,
|
||||
region=region,
|
||||
detail_region_info=road_address or "",
|
||||
)
|
||||
prompt = chatgpt_service.build_market_analysis_prompt()
|
||||
raw_response = await chatgpt_service.generate(prompt)
|
||||
marketing_analysis = _parse_marketing_analysis(raw_response)
|
||||
|
||||
return {
|
||||
"image_list": scraper.image_link_list,
|
||||
"image_count": len(scraper.image_link_list) if scraper.image_link_list else 0,
|
||||
"processed_info": processed_info,
|
||||
"marketing_analysis": marketing_analysis,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user