initializare
This commit is contained in:
172
deployment/windows/scripts/setup_dev.ps1
Normal file
172
deployment/windows/scripts/setup_dev.ps1
Normal file
@@ -0,0 +1,172 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
BTGO Scraper - Setup Development Environment
|
||||
.DESCRIPTION
|
||||
Configureaza mediul de dezvoltare local (venv, dependente, browsere)
|
||||
.NOTES
|
||||
Echivalent PowerShell pentru scripts\setup_windows.bat
|
||||
Rulare: Right-click → "Run with PowerShell"
|
||||
#>
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$ScriptDir = Split-Path -Parent $PSCommandPath
|
||||
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
|
||||
|
||||
Set-Location $ProjectDir
|
||||
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host " BTGO SCRAPER - SETUP WINDOWS" -ForegroundColor Yellow
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "Working directory: $ProjectDir" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
# Verifică Python
|
||||
try {
|
||||
$pythonVersion = & python --version 2>&1
|
||||
Write-Host "[OK] Python gasit: $pythonVersion" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
} catch {
|
||||
Write-Host "[ERROR] Python nu este instalat!" -ForegroundColor Red
|
||||
Write-Host "Descarca Python de la: https://www.python.org/downloads/" -ForegroundColor Yellow
|
||||
Write-Host "Asigura-te ca bifezi 'Add Python to PATH' la instalare." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Verifică dacă venv există deja
|
||||
$venvPath = Join-Path $ProjectDir ".venv"
|
||||
if (Test-Path (Join-Path $venvPath "Scripts\Activate.ps1")) {
|
||||
Write-Host "[INFO] Virtual environment exista deja." -ForegroundColor Yellow
|
||||
$recreate = Read-Host "Doresti sa il stergi si sa recreezi? (y/N)"
|
||||
if ($recreate -eq "y" -or $recreate -eq "Y") {
|
||||
Write-Host "Stergere venv existent..." -ForegroundColor Yellow
|
||||
Remove-Item -Path $venvPath -Recurse -Force
|
||||
} else {
|
||||
# Skip la activare
|
||||
goto ActivateVenv
|
||||
}
|
||||
}
|
||||
|
||||
# Creează virtual environment
|
||||
Write-Host "[STEP 1/5] Creare virtual environment..." -ForegroundColor Cyan
|
||||
try {
|
||||
& python -m venv .venv
|
||||
Write-Host "[OK] Virtual environment creat." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
} catch {
|
||||
Write-Host "[ERROR] Nu am putut crea venv!" -ForegroundColor Red
|
||||
Write-Host "Eroare: $_" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
|
||||
:ActivateVenv
|
||||
# Activează venv
|
||||
Write-Host "[STEP 2/5] Activare virtual environment..." -ForegroundColor Cyan
|
||||
$activateScript = Join-Path $venvPath "Scripts\Activate.ps1"
|
||||
if (-not (Test-Path $activateScript)) {
|
||||
Write-Host "[ERROR] Nu am gasit scriptul de activare: $activateScript" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
|
||||
try {
|
||||
& $activateScript
|
||||
Write-Host "[OK] Virtual environment activat." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
} catch {
|
||||
Write-Host "[ERROR] Nu am putut activa venv!" -ForegroundColor Red
|
||||
Write-Host "Eroare: $_" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Instalează requirements
|
||||
Write-Host "[STEP 3/5] Instalare dependente Python..." -ForegroundColor Cyan
|
||||
try {
|
||||
& pip install --upgrade pip --quiet
|
||||
& pip install -r requirements.txt
|
||||
Write-Host "[OK] Dependente instalate." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
} catch {
|
||||
Write-Host "[ERROR] Instalare dependente esuata!" -ForegroundColor Red
|
||||
Write-Host "Eroare: $_" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Instalează browsere Playwright
|
||||
Write-Host "[STEP 4/5] Instalare browsere Playwright (Chromium)..." -ForegroundColor Cyan
|
||||
Write-Host "Acest pas poate dura cateva minute..." -ForegroundColor Yellow
|
||||
try {
|
||||
& playwright install chromium
|
||||
Write-Host "[OK] Browsere instalate." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
} catch {
|
||||
Write-Host "[ERROR] Instalare browsere esuata!" -ForegroundColor Red
|
||||
Write-Host "Eroare: $_" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Copiază .env.example la .env dacă nu există
|
||||
Write-Host "[STEP 5/5] Verificare configuratie..." -ForegroundColor Cyan
|
||||
$envFile = Join-Path $ProjectDir ".env"
|
||||
$envExample = Join-Path $ProjectDir ".env.example"
|
||||
|
||||
if (-not (Test-Path $envFile)) {
|
||||
if (Test-Path $envExample) {
|
||||
Write-Host "Creare fisier .env din template..." -ForegroundColor Yellow
|
||||
Copy-Item $envExample $envFile
|
||||
Write-Host "[INFO] Fisierul .env a fost creat." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "IMPORTANT: Editeaza .env si completeaza:" -ForegroundColor Yellow
|
||||
Write-Host " - BTGO_USERNAME=your_username" -ForegroundColor Gray
|
||||
Write-Host " - BTGO_PASSWORD=your_password" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
} else {
|
||||
Write-Host "[ERROR] .env.example nu exista!" -ForegroundColor Red
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Host "[OK] Fisierul .env exista deja." -ForegroundColor Green
|
||||
}
|
||||
|
||||
# Verifică directoarele
|
||||
$dataDir = Join-Path $ProjectDir "data"
|
||||
$logsDir = Join-Path $ProjectDir "logs"
|
||||
|
||||
if (-not (Test-Path $dataDir)) {
|
||||
New-Item -ItemType Directory -Path $dataDir | Out-Null
|
||||
}
|
||||
if (-not (Test-Path $logsDir)) {
|
||||
New-Item -ItemType Directory -Path $logsDir | Out-Null
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host " SETUP COMPLET!" -ForegroundColor Green
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "Next steps:" -ForegroundColor Cyan
|
||||
Write-Host " 1. Editeaza .env cu credentialele tale" -ForegroundColor Gray
|
||||
Write-Host " 2. Ruleaza scriptul run_scraper.ps1 sau run_telegram_bot.ps1" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "Pentru debugging selectors (optional):" -ForegroundColor Cyan
|
||||
Write-Host " .venv\Scripts\Activate.ps1" -ForegroundColor Gray
|
||||
Write-Host " playwright codegen https://btgo.ro --target python" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
Write-Host "Pentru detalii, vezi README.md" -ForegroundColor Gray
|
||||
Write-Host ("=" * 80) -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Read-Host "Apasa Enter pentru a inchide"
|
||||
Reference in New Issue
Block a user