@echo off
setlocal

:: Set the project folder to this script's directory
set "PROJECT_DIR=%~dp0"
cd /d "%PROJECT_DIR%"

:: Check if venv folder exists; if not, create venv and install requirements
if not exist "venv\Scripts\python.exe" (
    echo Creating virtual environment...
    python -m venv venv
    call venv\Scripts\activate.bat
    echo Installing required packages...
    pip install --upgrade pip
    pip install flask selenium webdriver-manager beautifulsoup4
) else (
    call venv\Scripts\activate.bat
)

:: Run the Flask server with logs redirected to server.log
echo Starting Flask server, logs will be written to server.log
start "" cmd /k "venv\Scripts\python.exe scraper_service.py"

endlocal
exit /b 0
