initializare

This commit is contained in:
2025-11-06 20:55:35 +02:00
commit 9956e9c11e
32 changed files with 5500 additions and 0 deletions

View File

@@ -0,0 +1,282 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
BTGO Telegram Bot - Complete Deployment Script
.DESCRIPTION
Deployment complet pentru bot-ul Telegram pe Windows VM
Verifica dependente, instaleaza requirements, configureaza serviciul
.NOTES
Rulare: Right-click → "Run with PowerShell" (ca Administrator)
#>
# Error handling
$ErrorActionPreference = "Stop"
# ============================================================================
# FUNCTIONS
# ============================================================================
function Write-ColorOutput {
param(
[string]$Message,
[string]$Color = "White",
[string]$Prefix = ""
)
$prefixColor = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[EROARE]" { "Red" }
"[AVERTIZARE]" { "Yellow" }
default { "White" }
}
if ($Prefix) {
Write-Host $Prefix -ForegroundColor $prefixColor -NoNewline
Write-Host " $Message" -ForegroundColor $Color
} else {
Write-Host $Message -ForegroundColor $Color
}
}
function Write-Separator {
param([string]$Title = "")
Write-Host ""
Write-Host "=" * 80 -ForegroundColor Cyan
if ($Title) {
Write-Host $Title -ForegroundColor Yellow
Write-Host "=" * 80 -ForegroundColor Cyan
}
}
# ============================================================================
# CONFIGURATION
# ============================================================================
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
$ServiceName = "BTGOTelegramBot"
Write-Separator "BTGO TELEGRAM BOT - DEPLOYMENT COMPLET"
Write-Host ""
Write-ColorOutput "Director proiect: $ProjectDir" -Prefix "[INFO]"
Write-Host ""
# ============================================================================
# [1/6] VERIFICARE PYTHON
# ============================================================================
Write-Separator "[1/6] VERIFICARE PYTHON"
try {
$pythonVersion = python --version 2>&1
if ($LASTEXITCODE -ne 0) { throw }
Write-ColorOutput "Python gasit: $pythonVersion" -Prefix "[OK]"
} catch {
Write-ColorOutput "Python nu este instalat sau nu este in PATH!" -Prefix "[EROARE]"
Write-Host ""
Write-Host "Instaleaza Python 3.11+ de la: https://www.python.org/downloads/"
Write-Host "Asigura-te ca bifezi 'Add Python to PATH' la instalare"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# ============================================================================
# [2/6] VERIFICARE FISIERE PROIECT
# ============================================================================
Write-Separator "[2/6] VERIFICARE FISIERE PROIECT"
$criticalFiles = @(
"telegram_trigger_bot.py",
"btgo_scraper.py",
"requirements.txt"
)
$filesOk = $true
foreach ($file in $criticalFiles) {
$filePath = Join-Path $ProjectDir $file
if (Test-Path $filePath) {
Write-ColorOutput "$file - OK" -Prefix "[OK]"
} else {
Write-ColorOutput "$file - LIPSESTE!" -Prefix "[EROARE]"
$filesOk = $false
}
}
if (-not $filesOk) {
Write-ColorOutput "Fisiere critice lipsesc din proiect!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# ============================================================================
# [3/6] VERIFICARE/CREARE .env
# ============================================================================
Write-Separator "[3/6] VERIFICARE CONFIGURARE (.env)"
$envFile = Join-Path $ProjectDir ".env"
$envExample = Join-Path $ProjectDir ".env.example"
if (-not (Test-Path $envFile)) {
if (Test-Path $envExample) {
Write-ColorOutput ".env nu exista. Copiem .env.example..." -Prefix "[INFO]"
Copy-Item $envExample $envFile
Write-ColorOutput ".env creat din .env.example" -Prefix "[OK]"
Write-Host ""
Write-ColorOutput "IMPORTANT: Editeaza .env si configureaza:" -Prefix "[AVERTIZARE]"
Write-Host " - TELEGRAM_BOT_TOKEN"
Write-Host " - TELEGRAM_ALLOWED_USER_IDS"
Write-Host " - TELEGRAM_CHAT_ID (optional)"
Write-Host " - LOGIN_ID si PAROLA pentru BTGO"
Write-Host ""
Read-Host "Apasa Enter dupa ce ai configurat .env"
} else {
Write-ColorOutput ".env si .env.example lipsesc!" -Prefix "[EROARE]"
Write-Host "Creaza manual .env cu variabilele necesare"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
}
# Verifică variabile critice
$envContent = Get-Content $envFile -Raw
if ($envContent -notmatch "TELEGRAM_BOT_TOKEN=(?!your_).+") {
Write-ColorOutput "TELEGRAM_BOT_TOKEN nu este configurat in .env!" -Prefix "[EROARE]"
Write-Host "Editeaza .env si adauga token-ul de la @BotFather"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
if ($envContent -notmatch "LOGIN_ID=(?!your_).+") {
Write-ColorOutput "LOGIN_ID nu este configurat in .env!" -Prefix "[AVERTIZARE]"
Write-Host "Scraper-ul nu va functiona fara credentiale BTGO"
}
Write-ColorOutput ".env exista si pare configurat" -Prefix "[OK]"
# ============================================================================
# [4/6] INSTALARE DEPENDENTE PYTHON
# ============================================================================
Write-Separator "[4/6] INSTALARE DEPENDENTE PYTHON"
try {
Write-ColorOutput "Upgrade pip..." -Prefix "[INFO]"
python -m pip install --upgrade pip --quiet
Write-ColorOutput "Instalare requirements.txt..." -Prefix "[INFO]"
$requirementsFile = Join-Path $ProjectDir "requirements.txt"
python -m pip install -r $requirementsFile
if ($LASTEXITCODE -ne 0) { throw }
Write-ColorOutput "Dependente instalate cu succes" -Prefix "[OK]"
} catch {
Write-ColorOutput "Instalarea dependentelor a esuat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# ============================================================================
# [5/6] INSTALARE PLAYWRIGHT BROWSERS (GLOBAL)
# ============================================================================
Write-Separator "[5/6] INSTALARE PLAYWRIGHT BROWSERS (GLOBAL)"
# Setează locație globală pentru browsere (accesibilă pentru serviciul SYSTEM)
$globalBrowserPath = "C:\playwright-browsers"
Write-ColorOutput "Configurare locatie globala browsere: $globalBrowserPath" -Prefix "[INFO]"
# Creează directorul dacă nu există
if (-not (Test-Path $globalBrowserPath)) {
New-Item -ItemType Directory -Path $globalBrowserPath -Force | Out-Null
Write-ColorOutput "Director creat: $globalBrowserPath" -Prefix "[OK]"
}
# Acordă permisiuni SYSTEM la director
Write-ColorOutput "Acordare permisiuni SYSTEM..." -Prefix "[INFO]"
icacls $globalBrowserPath /grant "SYSTEM:(OI)(CI)F" /T 2>&1 | Out-Null
# Setează environment variable la nivel de sistem
[System.Environment]::SetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH", $globalBrowserPath, [System.EnvironmentVariableTarget]::Machine)
$env:PLAYWRIGHT_BROWSERS_PATH = $globalBrowserPath
Write-ColorOutput "Environment variable setata: PLAYWRIGHT_BROWSERS_PATH" -Prefix "[OK]"
# Instalează browserele
try {
Write-ColorOutput "Instalare browsere Playwright in $globalBrowserPath..." -Prefix "[INFO]"
Write-Host "Aceasta poate dura 1-2 minute..." -ForegroundColor Gray
python -m playwright install chromium
if ($LASTEXITCODE -ne 0) { throw }
Write-ColorOutput "Playwright browsere instalate cu succes!" -Prefix "[OK]"
} catch {
Write-ColorOutput "Instalarea browserelor Playwright a esuat!" -Prefix "[AVERTIZARE]"
Write-Host "Scraper-ul poate sa nu functioneze corect"
}
# ============================================================================
# CREARE DIRECTOARE NECESARE
# ============================================================================
$dataDir = Join-Path $ProjectDir "data"
$logsDir = Join-Path $ProjectDir "logs"
if (-not (Test-Path $dataDir)) { New-Item -ItemType Directory -Path $dataDir -Force | Out-Null }
if (-not (Test-Path $logsDir)) { New-Item -ItemType Directory -Path $logsDir -Force | Out-Null }
Write-ColorOutput "Directoare create: data, logs" -Prefix "[OK]"
# ============================================================================
# [6/6] INSTALARE/RESTART SERVICIU
# ============================================================================
Write-Separator "[6/6] INSTALARE SERVICIU WINDOWS"
# Verifică dacă serviciul există
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($service) {
Write-ColorOutput "Serviciul exista deja. Reinstalam..." -Prefix "[INFO]"
& "$ScriptDir\uninstall_service.ps1"
Start-Sleep -Seconds 3
}
Write-ColorOutput "Rulare install_service.ps1..." -Prefix "[INFO]"
& "$ScriptDir\install_service.ps1"
if ($LASTEXITCODE -ne 0) {
Write-ColorOutput "Instalarea serviciului a esuat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# ============================================================================
# FINALIZARE
# ============================================================================
Write-Separator "[SUCCES] DEPLOYMENT FINALIZAT!"
Write-Host ""
Write-Host "Serviciul BTGO Telegram Bot este acum instalat si ruleaza." -ForegroundColor Green
Write-Host ""
Write-Host "Comenzi utile:" -ForegroundColor Yellow
Write-Host " - Status: Get-Service $ServiceName"
Write-Host " - Logs: Get-Content '$logsDir\telegram_bot_stdout.log' -Tail 20"
Write-Host " - Opreste: Stop-Service $ServiceName"
Write-Host " - Porneste: Start-Service $ServiceName"
Write-Host " - Restart: Restart-Service $ServiceName"
Write-Host " - Dezinstala: .\uninstall_service.ps1"
Write-Host ""
Write-Host "Teste bot Telegram:" -ForegroundColor Yellow
Write-Host " 1. Deschide Telegram si cauta bot-ul tau"
Write-Host " 2. Trimite /start pentru a vedea comenzile"
Write-Host " 3. Trimite /scrape pentru a testa scraper-ul"
Write-Host ""
Write-Host "Verificare logs in timp real:" -ForegroundColor Yellow
Write-Host " Get-Content '$logsDir\telegram_bot_stdout.log' -Wait"
Write-Host ""
Write-Separator
Read-Host "`nApasa Enter pentru a inchide"

View File

@@ -0,0 +1,275 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
BTGO Telegram Bot - Service Installation Script
.DESCRIPTION
Instalează bot-ul Telegram ca serviciu Windows folosind NSSM
.NOTES
Rulare: Right-click → "Run with PowerShell" (ca Administrator)
#>
$ErrorActionPreference = "Stop"
# ============================================================================
# FUNCTIONS
# ============================================================================
function Write-ColorOutput {
param(
[string]$Message,
[string]$Prefix = ""
)
$color = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[EROARE]" { "Red" }
"[AVERTIZARE]" { "Yellow" }
default { "White" }
}
if ($Prefix) {
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
Write-Host $Message
} else {
Write-Host $Message
}
}
function Write-Separator {
param([string]$Title = "")
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
if ($Title) {
Write-Host $Title -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
}
}
# ============================================================================
# CONFIGURATION
# ============================================================================
$ServiceName = "BTGOTelegramBot"
$ServiceDisplayName = "BTGO Telegram Trigger Bot"
$ServiceDescription = "Bot Telegram pentru declansarea BTGO Scraper prin comanda /scrape"
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
$BotScript = Join-Path $ProjectDir "telegram_trigger_bot.py"
$EnvFile = Join-Path $ProjectDir ".env"
$LogDir = Join-Path $ProjectDir "logs"
$ToolsDir = Join-Path $ProjectDir "deployment\windows\tools"
$NssmPath = Join-Path $ToolsDir "nssm.exe"
Write-Separator "BTGO TELEGRAM BOT - INSTALARE SERVICIU"
Write-ColorOutput "Director proiect: $ProjectDir" -Prefix "[INFO]"
# ============================================================================
# VERIFICARI PRE-INSTALARE
# ============================================================================
Write-Separator "VERIFICARI PRE-INSTALARE"
# Verifică Python
try {
$pythonPath = (Get-Command python).Source
Write-ColorOutput "Python: $pythonPath" -Prefix "[OK]"
} catch {
Write-ColorOutput "Python nu a fost gasit in PATH!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# Verifică script bot
if (Test-Path $BotScript) {
Write-ColorOutput "Script bot: $BotScript" -Prefix "[OK]"
} else {
Write-ColorOutput "Script bot nu a fost gasit: $BotScript" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# Verifică .env
if (Test-Path $EnvFile) {
Write-ColorOutput "Fisier .env: $EnvFile" -Prefix "[OK]"
} else {
Write-ColorOutput "Fisier .env nu a fost gasit: $EnvFile" -Prefix "[EROARE]"
Write-Host "Copiaza .env.example la .env si configureaza-l"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# Verifică variabile critice din .env
$envContent = Get-Content $EnvFile -Raw
if ($envContent -match "TELEGRAM_BOT_TOKEN=.+") {
Write-ColorOutput "TELEGRAM_BOT_TOKEN configurat in .env" -Prefix "[OK]"
} else {
Write-ColorOutput "TELEGRAM_BOT_TOKEN nu este setat in .env!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# Creează director logs
if (-not (Test-Path $LogDir)) {
New-Item -ItemType Directory -Path $LogDir -Force | Out-Null
Write-ColorOutput "Director logs creat: $LogDir" -Prefix "[INFO]"
}
# ============================================================================
# DOWNLOAD NSSM (daca nu exista)
# ============================================================================
if (-not (Test-Path $NssmPath)) {
Write-Separator "DOWNLOAD NSSM"
Write-ColorOutput "NSSM nu a fost gasit. Descarcam..." -Prefix "[INFO]"
if (-not (Test-Path $ToolsDir)) {
New-Item -ItemType Directory -Path $ToolsDir -Force | Out-Null
}
try {
$nssmUrl = "https://nssm.cc/release/nssm-2.24.zip"
$nssmZip = Join-Path $env:TEMP "nssm.zip"
$nssmExtract = Join-Path $env:TEMP "nssm"
Write-ColorOutput "Descarcare NSSM..." -Prefix "[INFO]"
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $nssmUrl -OutFile $nssmZip -UseBasicParsing
Write-ColorOutput "Extragere NSSM..." -Prefix "[INFO]"
Expand-Archive -Path $nssmZip -DestinationPath $nssmExtract -Force
# Copiază executabilul
$nssmExe = Join-Path $nssmExtract "nssm-2.24\win64\nssm.exe"
Copy-Item $nssmExe $NssmPath
# Curăță
Remove-Item $nssmZip -Force -ErrorAction SilentlyContinue
Remove-Item $nssmExtract -Recurse -Force -ErrorAction SilentlyContinue
Write-ColorOutput "NSSM descarcat: $NssmPath" -Prefix "[OK]"
} catch {
Write-ColorOutput "Descarcarea NSSM a esuat!" -Prefix "[EROARE]"
Write-Host "Descarca manual de la: https://nssm.cc/download"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
}
# ============================================================================
# INSTALARE SERVICIU
# ============================================================================
Write-Separator "INSTALARE SERVICIU WINDOWS"
# Verifică dacă serviciul există deja
$existingService = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($existingService) {
Write-ColorOutput "Serviciul $ServiceName exista deja!" -Prefix "[AVERTIZARE]"
Write-ColorOutput "Ruland dezinstalare mai intai..." -Prefix "[INFO]"
& "$ScriptDir\uninstall_service.ps1"
Start-Sleep -Seconds 3
}
Write-ColorOutput "Instalare serviciu: $ServiceName" -Prefix "[INFO]"
# Instalează serviciul
& $NssmPath install $ServiceName $pythonPath $BotScript
if ($LASTEXITCODE -ne 0) {
Write-ColorOutput "Instalarea serviciului a esuat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# ============================================================================
# CONFIGURARE SERVICIU
# ============================================================================
Write-ColorOutput "Configurare serviciu..." -Prefix "[INFO]"
# Display name si descriere
& $NssmPath set $ServiceName DisplayName $ServiceDisplayName
& $NssmPath set $ServiceName Description $ServiceDescription
# Verifică și configurează Playwright browsers global (dacă nu e deja setat)
$globalBrowserPath = [System.Environment]::GetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH", [System.EnvironmentVariableTarget]::Machine)
if (-not $globalBrowserPath) {
Write-ColorOutput "PLAYWRIGHT_BROWSERS_PATH nu este setat!" -Prefix "[AVERTIZARE]"
Write-Host "Ruleaza 'deploy.ps1' pentru instalare completa cu browsere globale"
} else {
Write-ColorOutput "Playwright browsere: $globalBrowserPath" -Prefix "[OK]"
}
# Working directory
& $NssmPath set $ServiceName AppDirectory $ProjectDir
# Stdout/Stderr logging
$stdoutLog = Join-Path $LogDir "telegram_bot_stdout.log"
$stderrLog = Join-Path $LogDir "telegram_bot_stderr.log"
& $NssmPath set $ServiceName AppStdout $stdoutLog
& $NssmPath set $ServiceName AppStderr $stderrLog
# Rotatie logs (10 MB max)
& $NssmPath set $ServiceName AppStdoutCreationDisposition 4
& $NssmPath set $ServiceName AppStderrCreationDisposition 4
& $NssmPath set $ServiceName AppRotateFiles 1
& $NssmPath set $ServiceName AppRotateOnline 1
& $NssmPath set $ServiceName AppRotateBytes 10485760
# Restart policy (restart la crash)
& $NssmPath set $ServiceName AppExit Default Restart
& $NssmPath set $ServiceName AppRestartDelay 5000
# Start mode (Automatic Delayed Start)
& $NssmPath set $ServiceName Start SERVICE_DELAYED_AUTO_START
Write-ColorOutput "Serviciu configurat cu succes!" -Prefix "[OK]"
# ============================================================================
# PORNIRE SERVICIU
# ============================================================================
Write-Separator "PORNIRE SERVICIU"
Write-ColorOutput "Pornire serviciu: $ServiceName" -Prefix "[INFO]"
Start-Service -Name $ServiceName
if ((Get-Service -Name $ServiceName).Status -ne "Running") {
Write-ColorOutput "Pornirea serviciului a esuat!" -Prefix "[EROARE]"
Write-Host "Verifica logurile in: $LogDir"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
Start-Sleep -Seconds 2
# ============================================================================
# VERIFICARE STATUS
# ============================================================================
$service = Get-Service -Name $ServiceName
if ($service.Status -eq "Running") {
Write-Separator "[SUCCES] SERVICIU INSTALAT SI PORNIT!"
Write-Host ""
Write-Host "Serviciu: $ServiceName" -ForegroundColor Green
Write-Host "Display: $ServiceDisplayName" -ForegroundColor Green
Write-Host "Script: $BotScript" -ForegroundColor Green
Write-Host "Logs: $LogDir" -ForegroundColor Green
Write-Host ""
Write-Host "Comenzi utile:" -ForegroundColor Yellow
Write-Host " - Opreste: Stop-Service $ServiceName"
Write-Host " - Porneste: Start-Service $ServiceName"
Write-Host " - Restart: Restart-Service $ServiceName"
Write-Host " - Status: Get-Service $ServiceName"
Write-Host " - Dezinstaleaza: .\uninstall_service.ps1"
Write-Host ""
Write-Separator
} else {
Write-ColorOutput "Serviciul este instalat dar nu ruleaza!" -Prefix "[AVERTIZARE]"
Write-Host "Verifica logurile: $LogDir"
Get-Service -Name $ServiceName | Format-List
}
Read-Host "`nApasa Enter pentru a inchide"

View File

@@ -0,0 +1,314 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
BTGO Telegram Bot - Main Menu Launcher
.DESCRIPTION
Meniu interactiv pentru toate scripturile de management
.NOTES
Rulare: Right-click → "Run with PowerShell" (ca Administrator)
#>
$ErrorActionPreference = "Continue"
$ScriptDir = Split-Path -Parent $PSCommandPath
$ServiceName = "BTGOTelegramBot"
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
$LogDir = Join-Path $ProjectDir "logs"
function Show-MainMenu {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host " BTGO TELEGRAM BOT - MANAGEMENT MENU" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
# Verifică status serviciu
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($service) {
if ($service.Status -eq "Running") {
Write-Host "Status: " -NoNewline
Write-Host "[RUNNING]" -ForegroundColor Green
} else {
Write-Host "Status: " -NoNewline
Write-Host "[STOPPED]" -ForegroundColor Yellow
}
} else {
Write-Host "Status: " -NoNewline
Write-Host "[NOT INSTALLED]" -ForegroundColor Red
}
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
Write-Host " [1] Deploy Complet (First Time Setup)" -ForegroundColor Cyan
Write-Host " [2] Install Service Only" -ForegroundColor Cyan
Write-Host " [3] Uninstall Service" -ForegroundColor Cyan
Write-Host ""
Write-Host " [4] Start Service" -ForegroundColor Green
Write-Host " [5] Stop Service" -ForegroundColor Yellow
Write-Host " [6] Restart Service" -ForegroundColor Magenta
Write-Host " [7] Service Status" -ForegroundColor White
Write-Host ""
Write-Host " [8] View Logs (Interactive)" -ForegroundColor White
Write-Host " [9] Quick Log Tail (Stdout)" -ForegroundColor White
Write-Host ""
Write-Host " Development & Manual Testing:" -ForegroundColor DarkCyan
Write-Host " [S] Setup Development Environment" -ForegroundColor Cyan
Write-Host " [R] Run Scraper (Manual)" -ForegroundColor Cyan
Write-Host " [T] Run Telegram Bot (Manual)" -ForegroundColor Cyan
Write-Host ""
Write-Host " [A] Open Deployment README" -ForegroundColor Gray
Write-Host " [B] Open Quick Start Guide" -ForegroundColor Gray
Write-Host " [C] Open Project in Explorer" -ForegroundColor Gray
Write-Host " [D] Open Logs in Explorer" -ForegroundColor Gray
Write-Host " [U] Update Browsers (Playwright)" -ForegroundColor Gray
Write-Host ""
Write-Host " [0] Exit" -ForegroundColor DarkGray
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
}
function Invoke-Deploy {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "RULARE DEPLOY COMPLET" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\deploy.ps1"
Read-Host "`nApasa Enter pentru a reveni la meniu"
}
function Invoke-Install {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "INSTALARE SERVICIU" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\install_service.ps1"
Read-Host "`nApasa Enter pentru a reveni la meniu"
}
function Invoke-Uninstall {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "DEZINSTALARE SERVICIU" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\uninstall_service.ps1"
Read-Host "`nApasa Enter pentru a reveni la meniu"
}
function Invoke-Start {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "START SERVICIU" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-Host "[EROARE] Serviciul $ServiceName nu este instalat!" -ForegroundColor Red
Start-Sleep -Seconds 2
return
}
Write-Host "[INFO] Pornire serviciu..." -ForegroundColor Cyan
try {
Start-Service -Name $ServiceName
Write-Host ""
Write-Host "[SUCCES] Serviciu pornit!" -ForegroundColor Green
} catch {
Write-Host ""
Write-Host "[EROARE] Pornirea a esuat: $_" -ForegroundColor Red
}
Start-Sleep -Seconds 3
}
function Invoke-Stop {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STOP SERVICIU" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-Host "[EROARE] Serviciul $ServiceName nu este instalat!" -ForegroundColor Red
Start-Sleep -Seconds 2
return
}
Write-Host "[INFO] Oprire serviciu..." -ForegroundColor Cyan
try {
Stop-Service -Name $ServiceName -Force
Write-Host ""
Write-Host "[SUCCES] Serviciu oprit!" -ForegroundColor Green
} catch {
Write-Host ""
Write-Host "[INFO] Serviciul era deja oprit" -ForegroundColor Yellow
}
Start-Sleep -Seconds 3
}
function Invoke-Restart {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "RESTART SERVICIU" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\restart_service.ps1"
Read-Host "`nApasa Enter pentru a reveni la meniu"
}
function Invoke-Status {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STATUS SERVICIU" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\status.ps1"
Read-Host "`nApasa Enter pentru a reveni la meniu"
}
function Invoke-ViewLogs {
Clear-Host
& "$ScriptDir\view_logs.ps1"
}
function Invoke-TailLogs {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "LOG TAIL - STDOUT (LIVE)" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "Apasa Ctrl+C pentru a opri" -ForegroundColor Yellow
Write-Host ""
$stdoutLog = Join-Path $LogDir "telegram_bot_stdout.log"
if (Test-Path $stdoutLog) {
Get-Content $stdoutLog -Wait -Tail 30
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Open-ReadmeFile {
$readme = Join-Path $ProjectDir "deployment\windows\README.md"
if (Test-Path $readme) {
Start-Process $readme
}
}
function Open-QuickStartFile {
$quickstart = Join-Path $ProjectDir "deployment\windows\QUICK_START.md"
if (Test-Path $quickstart) {
Start-Process $quickstart
}
}
function Open-ProjectExplorer {
Start-Process explorer $ProjectDir
}
function Open-LogsExplorer {
if (Test-Path $LogDir) {
Start-Process explorer $LogDir
} else {
Write-Host "[INFO] Directorul logs nu exista inca" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Invoke-SetupDev {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "SETUP DEVELOPMENT ENVIRONMENT" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\setup_dev.ps1"
}
function Invoke-RunScraper {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "RUN SCRAPER (MANUAL MODE)" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\run_scraper.ps1"
}
function Invoke-RunTelegramBotManual {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "RUN TELEGRAM BOT (MANUAL MODE)" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\run_telegram_bot_manual.ps1"
}
function Invoke-UpdateBrowsers {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "UPDATE PLAYWRIGHT BROWSERS" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
& "$ScriptDir\update_browsers.ps1"
Read-Host "`nApasa Enter pentru a reveni la meniu"
}
# Main loop
do {
Show-MainMenu
$choice = Read-Host "Selecteaza optiune"
switch ($choice) {
"1" { Invoke-Deploy }
"2" { Invoke-Install }
"3" { Invoke-Uninstall }
"4" { Invoke-Start }
"5" { Invoke-Stop }
"6" { Invoke-Restart }
"7" { Invoke-Status }
"8" { Invoke-ViewLogs }
"9" { Invoke-TailLogs }
"A" { Open-ReadmeFile }
"a" { Open-ReadmeFile }
"B" { Open-QuickStartFile }
"b" { Open-QuickStartFile }
"C" { Open-ProjectExplorer }
"c" { Open-ProjectExplorer }
"D" { Open-LogsExplorer }
"d" { Open-LogsExplorer }
"S" { Invoke-SetupDev }
"s" { Invoke-SetupDev }
"R" { Invoke-RunScraper }
"r" { Invoke-RunScraper }
"T" { Invoke-RunTelegramBotManual }
"t" { Invoke-RunTelegramBotManual }
"U" { Invoke-UpdateBrowsers }
"u" { Invoke-UpdateBrowsers }
"0" {
Write-Host ""
Write-Host "Goodbye!" -ForegroundColor Green
exit 0
}
default {
Write-Host "[EROARE] Optiune invalida!" -ForegroundColor Red
Start-Sleep -Seconds 1
}
}
} while ($true)

View File

@@ -0,0 +1,87 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
BTGO Telegram Bot - Service Restart Script
.DESCRIPTION
Restart rapid al serviciului
#>
$ErrorActionPreference = "Stop"
$ServiceName = "BTGOTelegramBot"
function Write-ColorOutput {
param([string]$Message, [string]$Prefix = "")
$color = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[EROARE]" { "Red" }
default { "White" }
}
if ($Prefix) {
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
Write-Host $Message
} else {
Write-Host $Message
}
}
function Write-Separator {
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "RESTART SERVICIU: $ServiceName" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
}
Write-Separator
# Verifică dacă serviciul există
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-ColorOutput "Serviciul $ServiceName nu este instalat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# Oprește serviciul
Write-ColorOutput "Oprire serviciu..." -Prefix "[INFO]"
try {
Stop-Service -Name $ServiceName -Force
Write-ColorOutput "Serviciu oprit" -Prefix "[OK]"
} catch {
Write-ColorOutput "Oprirea a esuat. Incercam oprire fortata..." -Prefix "[AVERTIZARE]"
sc.exe stop $ServiceName | Out-Null
}
Start-Sleep -Seconds 2
# Pornește serviciul
Write-ColorOutput "Pornire serviciu..." -Prefix "[INFO]"
try {
Start-Service -Name $ServiceName
Write-ColorOutput "Serviciu pornit" -Prefix "[OK]"
} catch {
Write-ColorOutput "Pornirea serviciului a esuat!" -Prefix "[EROARE]"
Write-Host "Verificati logurile pentru detalii"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
Start-Sleep -Seconds 2
# Verifică status
$service = Get-Service -Name $ServiceName
if ($service.Status -eq "Running") {
Write-Host ""
Write-ColorOutput "[SUCCES] Serviciu restartat cu succes!" -ForegroundColor Green
Write-Host ""
Get-Service -Name $ServiceName | Format-Table -AutoSize
} else {
Write-Host ""
Write-ColorOutput "Serviciul nu ruleaza dupa restart!" -Prefix "[EROARE]"
Get-Service -Name $ServiceName | Format-Table -AutoSize
}
Read-Host "`nApasa Enter pentru a inchide"

View File

@@ -0,0 +1,111 @@
<#
.SYNOPSIS
BTGO Scraper - Rulare Development
.DESCRIPTION
Ruleaza scraper-ul BTGO in modul development (cu browser vizibil)
.NOTES
Echivalent PowerShell pentru scripts\run_dev.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 - RULARE DEVELOPMENT" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
Write-Host "Working directory: $ProjectDir" -ForegroundColor Gray
Write-Host ""
# Verifică dacă venv există
$venvPath = Join-Path $ProjectDir ".venv"
$activateScript = Join-Path $venvPath "Scripts\Activate.ps1"
if (-not (Test-Path $activateScript)) {
Write-Host "[ERROR] Virtual environment nu exista sau este incomplet!" -ForegroundColor Red
Write-Host "Ruleaza intai: setup_dev.ps1" -ForegroundColor Yellow
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"
exit 1
}
# Activează venv
Write-Host "Activare virtual environment..." -ForegroundColor Cyan
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
}
# Verifică dacă .env există
$envFile = Join-Path $ProjectDir ".env"
$envExample = Join-Path $ProjectDir ".env.example"
if (-not (Test-Path $envFile)) {
Write-Host "[WARNING] Fisierul .env nu exista!" -ForegroundColor Yellow
if (Test-Path $envExample) {
Write-Host "Copiez din .env.example..." -ForegroundColor Yellow
Copy-Item $envExample $envFile
Write-Host ""
Write-Host "IMPORTANT: Editeaza .env cu credentialele tale!" -ForegroundColor Yellow
Start-Process notepad $envFile -Wait
Write-Host ""
Read-Host "Apasa Enter dupa ce salvezi .env"
} else {
Write-Host "[ERROR] .env.example nu exista!" -ForegroundColor Red
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"
exit 1
}
}
# Verifică directoare output
$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
}
# Rulează scraper
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "Pornire scraper..." -ForegroundColor Yellow
Write-Host "Browser-ul va fi vizibil pentru debugging." -ForegroundColor Gray
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
try {
& python btgo_scraper.py
} catch {
Write-Host ""
Write-Host "[ERROR] Executie esuata: $_" -ForegroundColor Red
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"
exit 1
}
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "Executie terminata." -ForegroundColor Green
Write-Host "Verifica rezultatele in:" -ForegroundColor Cyan
Write-Host " - data\solduri_*.csv" -ForegroundColor Gray
Write-Host " - data\tranzactii_*.csv" -ForegroundColor Gray
Write-Host " - logs\scraper_*.log" -ForegroundColor Gray
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"

View File

@@ -0,0 +1,81 @@
<#
.SYNOPSIS
Telegram Trigger Bot pentru BTGO - Rulare Manuala
.DESCRIPTION
Ruleaza Telegram bot-ul in modul manual (nu ca serviciu Windows)
.NOTES
Echivalent PowerShell pentru scripts\run_telegram_bot.bat
Rulare: Right-click → "Run with PowerShell"
Pentru a opri: Ctrl+C
#>
$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 " TELEGRAM TRIGGER BOT PENTRU BTGO" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
Write-Host "Working directory: $ProjectDir" -ForegroundColor Gray
Write-Host ""
# Verifică dacă venv există
$venvPath = Join-Path $ProjectDir ".venv"
$activateScript = Join-Path $venvPath "Scripts\Activate.ps1"
if (-not (Test-Path $activateScript)) {
Write-Host "[ERROR] Virtual environment nu exista!" -ForegroundColor Red
Write-Host "Ruleaza intai: setup_dev.ps1" -ForegroundColor Yellow
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"
exit 1
}
# Activează venv
Write-Host "Activare virtual environment..." -ForegroundColor Cyan
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
}
# Verifică .env
$envFile = Join-Path $ProjectDir ".env"
if (-not (Test-Path $envFile)) {
Write-Host "[ERROR] Fisierul .env nu exista!" -ForegroundColor Red
Write-Host "Configureaza .env cu TELEGRAM_BOT_TOKEN si TELEGRAM_ALLOWED_USER_IDS" -ForegroundColor Yellow
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"
exit 1
}
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "Pornire Telegram Bot..." -ForegroundColor Yellow
Write-Host "Bot-ul va astepta comenzi /scrape" -ForegroundColor Gray
Write-Host "Apasa Ctrl+C pentru a opri bot-ul" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
try {
& python telegram_trigger_bot.py
} catch {
Write-Host ""
Write-Host "[ERROR] Executie esuata: $_" -ForegroundColor Red
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"
exit 1
}
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"

View 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"

View File

@@ -0,0 +1,65 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
BTGO Telegram Bot - Start Service Script
.DESCRIPTION
Pornește serviciul Windows
#>
$ErrorActionPreference = "Stop"
$ServiceName = "BTGOTelegramBot"
function Write-ColorOutput {
param([string]$Message, [string]$Prefix = "")
$color = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[EROARE]" { "Red" }
default { "White" }
}
if ($Prefix) {
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
Write-Host $Message
} else {
Write-Host $Message
}
}
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "START SERVICIU: $ServiceName" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
# Verifică dacă serviciul există
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-ColorOutput "Serviciul $ServiceName nu este instalat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# Pornește serviciul
Write-ColorOutput "Pornire serviciu..." -Prefix "[INFO]"
try {
Start-Service -Name $ServiceName
Write-ColorOutput "Serviciu pornit cu succes!" -Prefix "[OK]"
Start-Sleep -Seconds 2
# Verifică status
$service = Get-Service -Name $ServiceName
Write-Host ""
Get-Service -Name $ServiceName | Format-Table -AutoSize
} catch {
Write-ColorOutput "Pornirea serviciului a esuat!" -Prefix "[EROARE]"
Write-Host "Eroare: $_" -ForegroundColor Red
Write-Host ""
Write-Host "Verificati logurile:" -ForegroundColor Yellow
Write-Host " Get-Content logs\telegram_bot_stderr.log"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
Read-Host "`nApasa Enter pentru a inchide"

View File

@@ -0,0 +1,101 @@
<#
.SYNOPSIS
BTGO Telegram Bot - Service Status Script
.DESCRIPTION
Afiseaza status detaliat al serviciului
#>
$ServiceName = "BTGOTelegramBot"
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
$LogDir = Join-Path $ProjectDir "logs"
function Write-ColorOutput {
param([string]$Message, [string]$Prefix = "")
$color = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[AVERTIZARE]" { "Yellow" }
default { "White" }
}
if ($Prefix) {
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
Write-Host $Message
} else {
Write-Host $Message -ForegroundColor $color
}
}
function Write-Separator {
param([string]$Title)
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host $Title -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
}
Write-Separator "BTGO TELEGRAM BOT - STATUS SERVICIU"
# Verifică dacă serviciul există
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-ColorOutput "Serviciul $ServiceName NU este instalat" -Prefix "[INFO]"
Write-Host ""
Write-Host "Pentru instalare, rulati:" -ForegroundColor Yellow
Write-Host " .\deploy.ps1"
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"
exit 0
}
# Afișează informații serviciu
Write-Host "[STATUS SERVICIU]" -ForegroundColor Yellow
$service | Format-Table -Property Status, Name, DisplayName, StartType -AutoSize
# Afișează configurație detaliată
Write-Host "[CONFIGURATIE SERVICIU]" -ForegroundColor Yellow
Get-WmiObject -Class Win32_Service -Filter "Name='$ServiceName'" |
Format-List Name, DisplayName, State, StartMode, PathName
# Verifică ultimele logs
$stdoutLog = Join-Path $LogDir "telegram_bot_stdout.log"
if (Test-Path $stdoutLog) {
Write-Host "[ULTIMELE 10 LINII DIN LOG]" -ForegroundColor Yellow
Get-Content $stdoutLog -Tail 10
Write-Host ""
} else {
Write-ColorOutput "Log stdout nu exista inca" -Prefix "[INFO]"
Write-Host ""
}
# Verifică erori
$stderrLog = Join-Path $LogDir "telegram_bot_stderr.log"
if (Test-Path $stderrLog) {
$errLines = (Get-Content $stderrLog).Count
if ($errLines -gt 0) {
Write-ColorOutput "Exista erori in stderr log ($errLines linii)" -Prefix "[AVERTIZARE]"
Write-Host "Ultimele 5 erori:"
Get-Content $stderrLog -Tail 5
Write-Host ""
}
}
# Comenzi utile
Write-Host "[COMENZI UTILE]" -ForegroundColor Yellow
Write-Host " - Restart: .\restart_service.ps1"
Write-Host " - View logs: .\view_logs.ps1"
Write-Host " - Dezinstaleaza: .\uninstall_service.ps1"
Write-Host " - Redeploy: .\deploy.ps1"
Write-Host ""
# PowerShell Quick Commands
Write-Host "[POWERSHELL COMMANDS]" -ForegroundColor Yellow
Write-Host " - Restart-Service $ServiceName"
Write-Host " - Stop-Service $ServiceName"
Write-Host " - Start-Service $ServiceName"
Write-Host " - Get-Content '$stdoutLog' -Wait -Tail 20"
Write-Host ""
Read-Host "Apasa Enter pentru a inchide"

View File

@@ -0,0 +1,133 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
BTGO Telegram Bot - Service Uninstall Script
.DESCRIPTION
Dezinstaleaza serviciul Windows BTGO Telegram Bot
.NOTES
Rulare: Right-click → "Run with PowerShell" (ca Administrator)
#>
$ErrorActionPreference = "Stop"
# ============================================================================
# CONFIGURATION
# ============================================================================
$ServiceName = "BTGOTelegramBot"
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
$NssmPath = Join-Path $ProjectDir "deployment\windows\tools\nssm.exe"
function Write-ColorOutput {
param([string]$Message, [string]$Prefix = "")
$color = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[EROARE]" { "Red" }
"[AVERTIZARE]" { "Yellow" }
default { "White" }
}
if ($Prefix) {
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
Write-Host $Message
} else {
Write-Host $Message
}
}
function Write-Separator {
param([string]$Title = "")
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
if ($Title) {
Write-Host $Title -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
}
}
# ============================================================================
# VERIFICARE SERVICIU
# ============================================================================
Write-Separator "DEZINSTALARE SERVICIU: $ServiceName"
Write-Host ""
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $service) {
Write-ColorOutput "Serviciul $ServiceName nu este instalat." -Prefix "[INFO]"
Write-Host "Nimic de dezinstalat."
Read-Host "`nApasa Enter pentru a inchide"
exit 0
}
# ============================================================================
# OPRIRE SERVICIU
# ============================================================================
Write-ColorOutput "Verificare status serviciu..." -Prefix "[INFO]"
if ($service.Status -eq "Running") {
Write-ColorOutput "Serviciul ruleaza. Oprire..." -Prefix "[INFO]"
try {
Stop-Service -Name $ServiceName -Force
Write-ColorOutput "Serviciu oprit cu succes" -Prefix "[OK]"
Start-Sleep -Seconds 2
} catch {
Write-ColorOutput "Oprirea serviciului a esuat!" -Prefix "[AVERTIZARE]"
Write-ColorOutput "Incercam oprire fortata..." -Prefix "[INFO]"
sc.exe stop $ServiceName | Out-Null
Start-Sleep -Seconds 5
}
} else {
Write-ColorOutput "Serviciul este deja oprit" -Prefix "[INFO]"
}
# ============================================================================
# DEZINSTALARE SERVICIU
# ============================================================================
Write-ColorOutput "Dezinstalare serviciu..." -Prefix "[INFO]"
try {
if (Test-Path $NssmPath) {
# Folosește NSSM pentru dezinstalare
& $NssmPath remove $ServiceName confirm
if ($LASTEXITCODE -ne 0) { throw }
} else {
# Fallback la sc delete
Write-ColorOutput "NSSM nu a fost gasit, folosim sc delete" -Prefix "[INFO]"
sc.exe delete $ServiceName | Out-Null
if ($LASTEXITCODE -ne 0) { throw }
}
} catch {
Write-ColorOutput "Dezinstalarea serviciului a esuat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# ============================================================================
# VERIFICARE FINALA
# ============================================================================
Start-Sleep -Seconds 2
$serviceCheck = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $serviceCheck) {
Write-Separator "[SUCCES] SERVICIU DEZINSTALAT CU SUCCES!"
Write-Host ""
Write-Host "Serviciul $ServiceName a fost eliminat din sistem." -ForegroundColor Green
Write-Host ""
Write-Host "Pentru a reinstala serviciul, rulati:" -ForegroundColor Yellow
Write-Host " .\install_service.ps1"
Write-Host ""
Write-Separator
} else {
Write-ColorOutput "Serviciul pare sa mai existe in sistem!" -Prefix "[AVERTIZARE]"
Write-Host "Poate fi nevoie de un restart al sistemului."
Get-Service -Name $ServiceName | Format-List
}
Read-Host "`nApasa Enter pentru a inchide"

View File

@@ -0,0 +1,103 @@
#Requires -RunAsAdministrator
<#
.SYNOPSIS
Update Playwright Browsers (Global Location)
.DESCRIPTION
Actualizeaza browserele Playwright in locatia globala
Foloseste aceasta comanda pentru update-uri de browsere
#>
$ErrorActionPreference = "Stop"
$ServiceName = "BTGOTelegramBot"
function Write-ColorOutput {
param([string]$Message, [string]$Prefix = "")
$color = switch ($Prefix) {
"[OK]" { "Green" }
"[INFO]" { "Cyan" }
"[EROARE]" { "Red" }
"[AVERTIZARE]" { "Yellow" }
default { "White" }
}
if ($Prefix) {
Write-Host "$Prefix " -ForegroundColor $color -NoNewline
Write-Host $Message
} else {
Write-Host $Message -ForegroundColor $color
}
}
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "UPDATE PLAYWRIGHT BROWSERS" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
# Verifică environment variable
$globalBrowserPath = [System.Environment]::GetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH", [System.EnvironmentVariableTarget]::Machine)
if (-not $globalBrowserPath) {
$globalBrowserPath = "C:\playwright-browsers"
Write-ColorOutput "PLAYWRIGHT_BROWSERS_PATH nu este setat. Folosim: $globalBrowserPath" -Prefix "[AVERTIZARE]"
# Setează environment variable
[System.Environment]::SetEnvironmentVariable("PLAYWRIGHT_BROWSERS_PATH", $globalBrowserPath, [System.EnvironmentVariableTarget]::Machine)
Write-ColorOutput "Environment variable setata" -Prefix "[OK]"
}
$env:PLAYWRIGHT_BROWSERS_PATH = $globalBrowserPath
Write-ColorOutput "Locatie browsere: $globalBrowserPath" -Prefix "[INFO]"
# Creează director dacă nu există
if (-not (Test-Path $globalBrowserPath)) {
New-Item -ItemType Directory -Path $globalBrowserPath -Force | Out-Null
icacls $globalBrowserPath /grant "SYSTEM:(OI)(CI)F" /T 2>&1 | Out-Null
Write-ColorOutput "Director creat cu permisiuni SYSTEM" -Prefix "[OK]"
}
# Update browsere
Write-Host ""
Write-ColorOutput "Instalare/Update browsere Playwright..." -Prefix "[INFO]"
Write-Host "Aceasta poate dura 1-2 minute..." -ForegroundColor Gray
Write-Host ""
try {
python -m playwright install chromium
if ($LASTEXITCODE -ne 0) { throw }
Write-Host ""
Write-ColorOutput "Browsere actualizate cu succes!" -Prefix "[OK]"
} catch {
Write-ColorOutput "Update-ul browserelor a esuat!" -Prefix "[EROARE]"
Read-Host "`nApasa Enter pentru a inchide"
exit 1
}
# Restart serviciu dacă rulează
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($service) {
Write-Host ""
Write-ColorOutput "Restart serviciu..." -Prefix "[INFO]"
if ($service.Status -eq "Running") {
Restart-Service -Name $ServiceName -Force
Start-Sleep -Seconds 3
$service = Get-Service -Name $ServiceName
if ($service.Status -eq "Running") {
Write-ColorOutput "Serviciu restartat cu succes!" -Prefix "[OK]"
} else {
Write-ColorOutput "Serviciul nu a pornit" -Prefix "[AVERTIZARE]"
}
} else {
Write-ColorOutput "Serviciul nu rula" -Prefix "[INFO]"
}
}
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Green
Write-Host "[SUCCES] BROWSERE ACTUALIZATE!" -ForegroundColor Green
Write-Host ("=" * 80) -ForegroundColor Green
Read-Host "`nApasa Enter pentru a inchide"

View File

@@ -0,0 +1,137 @@
<#
.SYNOPSIS
BTGO Telegram Bot - View Logs Script
.DESCRIPTION
Afiseaza logurile serviciului in timp real
#>
$ScriptDir = Split-Path -Parent $PSCommandPath
$ProjectDir = Resolve-Path (Join-Path $ScriptDir "..\..\..") | Select-Object -ExpandProperty Path
$LogDir = Join-Path $ProjectDir "logs"
$StdoutLog = Join-Path $LogDir "telegram_bot_stdout.log"
$StderrLog = Join-Path $LogDir "telegram_bot_stderr.log"
function Show-Menu {
Clear-Host
Write-Host ""
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host " BTGO TELEGRAM BOT - VIEWER LOGS" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
Write-Host "Logs directory: $LogDir" -ForegroundColor Cyan
Write-Host ""
Write-Host "Selecteaza optiune:" -ForegroundColor Yellow
Write-Host ""
Write-Host " 1. Vizualizare stdout (output normal)"
Write-Host " 2. Vizualizare stderr (erori)"
Write-Host " 3. Tail stdout (timp real - ultim 30 linii)"
Write-Host " 4. Tail stderr (timp real - ultim 30 linii)"
Write-Host " 5. Deschide director logs in Explorer"
Write-Host " 6. Sterge toate logurile"
Write-Host " 0. Iesire"
Write-Host ""
}
function View-Stdout {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDOUT LOG" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StdoutLog) {
Get-Content $StdoutLog
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
}
Write-Host ""
Read-Host "Apasa Enter pentru a reveni la meniu"
}
function View-Stderr {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDERR LOG" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StderrLog) {
Get-Content $StderrLog
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
}
Write-Host ""
Read-Host "Apasa Enter pentru a reveni la meniu"
}
function Tail-Stdout {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDOUT TAIL - TIMP REAL (Apasa Ctrl+C pentru a opri)" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StdoutLog) {
Get-Content $StdoutLog -Wait -Tail 30
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Tail-Stderr {
Clear-Host
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host "STDERR TAIL - TIMP REAL (Apasa Ctrl+C pentru a opri)" -ForegroundColor Yellow
Write-Host ("=" * 80) -ForegroundColor Cyan
Write-Host ""
if (Test-Path $StderrLog) {
Get-Content $StderrLog -Wait -Tail 30
} else {
Write-Host "[INFO] Log-ul nu exista inca" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Open-LogsExplorer {
if (Test-Path $LogDir) {
explorer $LogDir
} else {
Write-Host "[INFO] Directorul logs nu exista" -ForegroundColor Yellow
Start-Sleep -Seconds 2
}
}
function Clear-AllLogs {
Write-Host ""
Write-Host "[AVERTIZARE] Stergi TOATE logurile?" -ForegroundColor Yellow
$confirm = Read-Host "Confirma (Y/N)"
if ($confirm -eq "Y" -or $confirm -eq "y") {
Remove-Item (Join-Path $LogDir "*.log") -Force -ErrorAction SilentlyContinue
Write-Host "[OK] Loguri sterse" -ForegroundColor Green
} else {
Write-Host "[INFO] Anulat" -ForegroundColor Cyan
}
Start-Sleep -Seconds 2
}
# Main loop
do {
Show-Menu
$choice = Read-Host "Optiune (0-6)"
switch ($choice) {
"1" { View-Stdout }
"2" { View-Stderr }
"3" { Tail-Stdout }
"4" { Tail-Stderr }
"5" { Open-LogsExplorer }
"6" { Clear-AllLogs }
"0" {
Write-Host ""
Write-Host "Bye!" -ForegroundColor Green
exit 0
}
default {
Write-Host "[EROARE] Optiune invalida!" -ForegroundColor Red
Start-Sleep -Seconds 1
}
}
} while ($true)