#!/bin/bash
# Start Chefkoch Scraper v4 safely as background daemon
# Place this in ~/.hermes/scripts/ and chmod +x
LOG="/home/debian/.hermes/profiles/nutrition-coach/scraper_v4.out"
PIDFILE="/tmp/chefkoch_scraper_v4.pid"

# Check if already running
if [ -f "$PIDFILE" ] && kill -0 "$(cat $PIDFILE)" 2>/dev/null; then
    echo "Scraper already running (PID $(cat $PIDFILE))"
    exit 0
fi

cd /home/debian/.hermes/profiles/nutrition-coach || exit 1

export PYTHONUNBUFFERED=1
export PLAYWRIGHT_BROWSERS_PATH=/home/debian/.cache/ms-playwright

nohup python3 /home/debian/.hermes/scripts/chefkoch_scraper_v4.py > "$LOG" 2>&1 &
PID=$!
echo $PID > "$PIDFILE"
echo "Scraper started (PID $PID). Log: $LOG"
