Skip to content

Latest commit

 

History

History
272 lines (206 loc) · 7.05 KB

File metadata and controls

272 lines (206 loc) · 7.05 KB

Executor Collect Restaurant Menu

대량 식당 메뉴 데이터 수집 실행기

📚 개요

CSV 파일에서 식당 목록을 로드하고, 지역별로 필터링하여 체계적으로 메뉴 정보를 수집하는 스크립트입니다.

주요 기능

  • ✅ CSV 파일에서 식당 목록 로드 및 지역 필터링
  • ✅ 수집 상태 관리 (success, failed, pending)
  • ✅ 진행 상황 JSON 파일로 저장 및 추적
  • ✅ 중단/재개 가능
  • ✅ 실패한 항목만 선택적 재수집
  • ✅ 주기적 자동 저장 (기본 10개마다)

🚀 사용 방법

1️⃣ 새로운 수집 시작

python executor_collect_restaurant_menu.py \
  --csv "식품_일반음식점.csv" \
  --region "노원구"

출력 파일: data/노원구_restaurants_progress_TIMESTAMP.json

2️⃣ 기존 작업 재개 (실패/미수집 모두 재시도)

python executor_collect_restaurant_menu.py \
  --resume "data/노원구_restaurants_progress_20260215_123456.json"

3️⃣ 기존 작업 재개 (실패 항목 스킵, 미수집만)

python executor_collect_restaurant_menu.py \
  --resume "data/노원구_restaurants_progress_20260215_123456.json" \
  --skip-failed

4️⃣ 고급 옵션

python executor_collect_restaurant_menu.py \
  --resume "data/노원구_restaurants_progress_20260215_123456.json" \
  --delay 3.0 \
  --save-interval 5 \
  --skip-failed

📋 명령줄 옵션

새로운 수집

옵션 설명 기본값
--csv 식당 CSV 파일 경로 필수
--region 필터링할 지역명 (예: "노원구") 필수
--encoding CSV 파일 인코딩 cp949
--output 출력 파일 경로 자동 생성

재개

옵션 설명
--resume 재개할 진행 상황 JSON 파일
--skip-failed 실패한 항목 스킵 (pending만 수집)

공통 옵션

옵션 설명 기본값
--delay 요청 간 대기 시간 (초) 2.0
--save-interval 몇 개마다 저장할지 10

📊 데이터 구조

진행 상황 파일 (*_progress.json)

{
  "metadata": {
    "region": "노원구",
    "created_at": "2026-02-15T10:00:00",
    "last_updated": "2026-02-15T12:30:00",
    "total": 500,
    "pending": 100,
    "success": 350,
    "failed": 50,
    "success_rate": "70.0%"
  },
  "restaurants": [
    {
      "unique_id": "abc123...",
      "business_name": "푸른스시",
      "business_status": "영업",
      "road_address": "서울특별시 노원구 월계로 123",
      "jibun_address": "서울특별시 노원구 월계동 123-45",
      "query": "서울특별시 노원구 푸른스시",
      "collection_status": "success",
      "collection_attempts": 1,
      "last_attempt_at": "2026-02-15T10:05:00",
      "place_id": "1769424895",
      "name": "푸른스시 광운대본점",
      "category": ["일식", "초밥,롤"],
      "address": "서울특별시 노원구 월계동 402-19",
      "url": "https://map.naver.com/...",
      "short_url": "https://naver.me/GYC6tGbl",
      "short_hash": "GYC6tGbl",
      "menus": [
        {
          "name": "오늘의초밥 11pcs",
          "price": "13000",
          "description": "",
          "recommend": true,
          "image_url": "https://..."
        }
      ],
      "error_message": null
    }
  ]
}

수집 상태

  • pending: 아직 수집 안 함
  • success: 수집 성공
  • failed: 수집 실패

🔄 워크플로우

새로운 수집

CSV 로드 → 지역 필터링 → 진행 상황 파일 생성 → 순차 수집 → 주기적 저장

재개

진행 상황 파일 로드 → 수집 대상 필터링 → 순차 수집 → 주기적 저장

🧪 테스트

python test_executor_collect_restaurant_menu.py

테스트 내용:

  1. 고유 ID 생성 테스트
  2. CSV 로드 및 필터링 테스트
  3. 진행 상황 파일 생성/저장/로드 테스트
  4. 수집 상태 업데이트 시뮬레이션
  5. 재개 로직 시뮬레이션

📂 파일 구조

DataCollection/
├── executor_collect_restaurant_menu.py  # 메인 실행기
├── test_executor_collect_restaurant_menu.py  # 테스트 스크립트
├── sample_restaurants.csv  # 샘플 CSV
├── data/
│   └── *_restaurants_progress_*.json  # 진행 상황 파일
└── test_data/  # 테스트 데이터 (자동 생성)

⚠️ 주의사항

  1. 대용량 수집 시: --delay 값을 충분히 크게 설정 (3초 이상 권장)
  2. 중단 시: Ctrl+C로 안전하게 중단 가능 (자동 저장)
  3. 재개 시: 항상 최신 *_progress.json 파일 사용
  4. 실패 항목: --skip-failed 사용으로 시간 절약 가능

💡 팁

지역별 수집 전략

# 1단계: 전체 수집 시도
python executor_collect_restaurant_menu.py \
  --csv "식품_일반음식점.csv" \
  --region "노원구"

# 2단계: 실패/미수집 재시도
python executor_collect_restaurant_menu.py \
  --resume "data/노원구_restaurants_progress_*.json"

# 3단계: 실패 제외하고 미수집만 재시도
python executor_collect_restaurant_menu.py \
  --resume "data/노원구_restaurants_progress_*.json" \
  --skip-failed

성능 최적화

  • --save-interval 20: 더 적게 저장 (더 빠름, 위험 증가)
  • --save-interval 5: 더 자주 저장 (더 느림, 안전)
  • --delay 1.0: 빠른 수집 (차단 위험)
  • --delay 3.0: 안전한 수집 (느림)

🔗 관련 파일

  • collect_restaurant_menu_data.py: 단일 식당 수집 로직
  • collect_area_menus.py: 기본 함수들
  • run_area_collection.py: 지역별 대량 수집 (다른 방식)

📝 예시

노원구 전체 식당 수집

# 새로운 수집
python executor_collect_restaurant_menu.py \
  --csv "식품_일반음식점.csv" \
  --region "노원구" \
  --delay 2.5 \
  --save-interval 10

# 중단 후 재개
python executor_collect_restaurant_menu.py \
  --resume "data/노원구_restaurants_progress_20260215_100000.json"

# 실패 제외 재수집
python executor_collect_restaurant_menu.py \
  --resume "data/노원구_restaurants_progress_20260215_100000.json" \
  --skip-failed

여러 구 순차 수집

# 노원구
python executor_collect_restaurant_menu.py --csv "식품_일반음식점.csv" --region "노원구"

# 강남구
python executor_collect_restaurant_menu.py --csv "식품_일반음식점.csv" --region "강남구"

# 강동구
python executor_collect_restaurant_menu.py --csv "식품_일반음식점.csv" --region "강동구"

🆘 문제 해결

수집이 실패하는 경우

  1. --delay 값 증가
  2. 네트워크 연결 확인
  3. 진행 상황 파일 확인 (error_message 필드)

중단 후 재개 안 되는 경우

  1. 최신 *_progress.json 파일 확인
  2. JSON 파일 손상 여부 확인
  3. 경로 확인

메모리 부족

  1. --save-interval 값 감소 (더 자주 저장)
  2. 지역을 더 세분화 (동 단위로)

만든 이: Claude Code + Anthropic 버전: 1.0.0 날짜: 2026-02-15