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

322
deployment/windows/INDEX.md Normal file
View File

@@ -0,0 +1,322 @@
# 📁 Deployment Scripts - Index
Structura completă de scripturi pentru deployment Windows Service.
## 📂 Structura Directoarelor
```
deployment/windows/
├── README.md # Documentație completă
├── QUICK_START.md # Ghid rapid 5 minute
├── INDEX.md # Acest fișier
├── scripts/ # Scripturi PowerShell
│ ├── menu.ps1 # ⭐ Meniu interactiv (START HERE)
│ ├── deploy.ps1 # 🚀 Deployment complet
│ ├── install_service.ps1 # Instalare serviciu Windows
│ ├── uninstall_service.ps1 # Dezinstalare serviciu
│ ├── restart_service.ps1 # Restart rapid serviciu
│ ├── status.ps1 # Status serviciu și logs
│ └── view_logs.ps1 # Viewer logs interactiv
└── tools/ # Binare (auto-download)
├── .gitignore
└── nssm.exe # Downloaded by install_service
```
---
## 🚦 Quick Navigation
| Dacă vrei să... | Rulează |
|-----------------|---------|
| **⭐ Meniu interactiv** | `menu.ps1` |
| **🆕 Instalezi prima dată** | `deploy.ps1` |
| **📊 Verifici statusul** | `status.ps1` |
| **🔄 Restarți serviciul** | `restart_service.ps1` |
| **📝 Vezi logs-uri** | `view_logs.ps1` |
| **🗑️ Dezinstalezi** | `uninstall_service.ps1` |
| **📖 Citești ghidul** | `README.md` sau `QUICK_START.md` |
**💡 TIP:** Folosește `menu.ps1` pentru o experiență user-friendly!
---
## 📜 Descriere Scripturi
### 🚀 `deploy.bat` (Main Script)
**Scop:** Deployment complet one-click
**Ce face:**
1. Verifică Python și dependențe
2. Configurează `.env` (dacă nu există)
3. Instalează requirements Python
4. Instalează browsere Playwright
5. Creează și pornește serviciul Windows
6. Verifică status final
**Rulare:**
```batch
cd deployment\windows\scripts
deploy.bat
```
**Durată:** 2-5 minute (prima dată)
**Note:**
- Necesită Administrator
- Interactiv (așteaptă configurare `.env`)
---
### ⚙️ `install_service.bat`
**Scop:** Instalează DOAR serviciul Windows (fără dependențe)
**Ce face:**
1. Descarcă NSSM (dacă lipsește)
2. Verifică `.env` și bot script
3. Instalează serviciu cu NSSM
4. Configurează logging, restart policy
5. Pornește serviciul
**Rulare:**
```batch
install_service.bat
```
**Use case:** După ce ai instalat manual Python + requirements
---
### 🗑️ `uninstall_service.bat`
**Scop:** Elimină serviciul din Windows
**Ce face:**
1. Oprește serviciul (dacă rulează)
2. Dezinstalează cu NSSM
3. Verifică eliminare completă
**Rulare:**
```batch
uninstall_service.bat
```
**Note:**
- NU șterge fișiere proiect
- NU șterge logs
- Doar elimină serviciul din registry
---
### 🔄 `restart_service.bat`
**Scop:** Restart rapid serviciu (după modificări cod)
**Ce face:**
1. Stop serviciu
2. Wait 2 secunde
3. Start serviciu
4. Verifică status
**Rulare:**
```batch
restart_service.bat
```
**Use case:** După `git pull` sau modificări `.env`
---
### 📊 `status.bat`
**Scop:** Status detaliat serviciu + logs
**Ce face:**
1. Verifică dacă serviciul există
2. Afișează status detaliat (`sc query`)
3. Afișează configurație (`sc qc`)
4. Afișează ultimele 10 linii din logs
5. Afișează comenzi utile
**Rulare:**
```batch
status.bat
```
**Use case:** Quick health check
---
### 📝 `view_logs.bat`
**Scop:** Viewer interactiv logs
**Meniu:**
1. View stdout (toate logs)
2. View stderr (doar erori)
3. Tail stdout (live updates)
4. Tail stderr (live erori)
5. Open Explorer în folder logs
6. Șterge toate logs
**Rulare:**
```batch
view_logs.bat
```
**Use case:** Debugging, monitoring live
---
## 🔧 Configurare Serviciu Windows
### Detalii Serviciu
| Proprietate | Valoare |
|------------|---------|
| **Service Name** | `BTGOTelegramBot` |
| **Display Name** | `BTGO Telegram Trigger Bot` |
| **Executable** | `python.exe` |
| **Arguments** | `telegram_trigger_bot.py` |
| **Working Dir** | Project root |
| **Start Type** | Automatic (Delayed) |
| **Restart Policy** | On failure, 5s delay |
| **Stdout Log** | `logs/telegram_bot_stdout.log` |
| **Stderr Log** | `logs/telegram_bot_stderr.log` |
| **Log Rotation** | 10 MB max |
### Managed by NSSM
**NSSM** (Non-Sucking Service Manager) este folosit pentru:
- ✅ Simplifică crearea serviciilor din Python scripts
- ✅ Gestionează logging automat
- ✅ Auto-restart la crash
- ✅ Gestiune environment variables
**Download:** Auto-descărcat de `install_service.bat` în `tools/nssm.exe`
**Versiune:** 2.24 (64-bit)
---
## 📋 Workflow Tipic
### Prima Instalare (VM nou)
```batch
# 1. Clone repo
cd E:\proiecte
git clone <repo> btgo-playwright
cd btgo-playwright
# 2. Configurează .env
copy .env.example .env
notepad .env
# 3. Deploy complet
cd deployment\windows\scripts
deploy.bat
# 4. Verifică status
status.bat
# 5. Test în Telegram
# Trimite /start la bot
```
---
### Update Cod (după modificări)
```batch
# 1. Pull changes
cd E:\proiecte\btgo-playwright
git pull
# 2. Update requirements (dacă s-au modificat)
python -m pip install -r requirements.txt
# 3. Restart serviciu
deployment\windows\scripts\restart_service.bat
# 4. Verifică logs
deployment\windows\scripts\view_logs.bat
```
---
### Debug Issues
```batch
# 1. Verifică status
deployment\windows\scripts\status.bat
# 2. Verifică logs
deployment\windows\scripts\view_logs.bat
# Selectează opțiunea 2 (stderr)
# 3. Testează manual (dacă e nevoie)
net stop BTGOTelegramBot
python telegram_trigger_bot.py
# Vezi output direct în terminal
# 4. Restart serviciu
deployment\windows\scripts\restart_service.bat
```
---
### Reinstalare Completă
```batch
# 1. Dezinstalează
deployment\windows\scripts\uninstall_service.bat
# 2. Șterge logs vechi (opțional)
del /q logs\*.log
# 3. Reinstalează
deployment\windows\scripts\deploy.bat
```
---
## 🛡️ Securitate
**Protecție `.env`:**
- `.env` este în `.gitignore` (nu se commitează)
- Conține credențiale sensibile (bot token, parole BTGO)
- Setează permissions doar pentru Administrator
**User IDs Telegram:**
- `TELEGRAM_ALLOWED_USER_IDS` restricționează accesul
- Format: `123456789,987654321` (comma-separated)
- Nu lăsa gol (permite oricui)
---
## 📞 Support
**Documentație:**
- `README.md` - Documentație completă
- `QUICK_START.md` - Ghid rapid 5 minute
- `../../TELEGRAM_BOT_SETUP.md` - Setup Telegram
- `../../CLAUDE.md` - Documentație proiect
**Troubleshooting:**
1. Verifică `status.bat`
2. Verifică `view_logs.bat` → stderr
3. Testează manual: `python telegram_trigger_bot.py`
---
## 📄 Changelog
| Data | Versiune | Modificări |
|------|----------|-----------|
| 2025-11-06 | 1.0 | Initial release - Complete deployment suite |
---
**Happy Deploying! 🚀**

View File

@@ -0,0 +1,264 @@
# 🚀 Quick Start - BTGO Telegram Bot pe VM Windows
Ghid rapid pentru deployment în 5 minute.
## ✅ Pre-requisites Checklist
- [ ] Windows Server/Desktop cu GUI (pentru browser vizibil)
- [ ] Python 3.11+ instalat în PATH
- [ ] Cont Administrator pe Windows
- [ ] Bot Telegram creat cu @BotFather
- [ ] Credențiale BTGO (LOGIN_ID + PAROLA)
---
## 📥 Pas 1: Clone Repository (pe VM)
```batch
cd E:\proiecte
git clone <repo-url> btgo-playwright
cd btgo-playwright
```
Sau copiază manualmente folderul pe VM.
---
## ⚙️ Pas 2: Configurare `.env`
```batch
REM Copiază template
copy .env.example .env
REM Editează cu Notepad
notepad .env
```
**Configurare minimă necesară:**
```ini
# TELEGRAM
TELEGRAM_BOT_TOKEN=123456:ABC-DEF... # De la @BotFather
TELEGRAM_ALLOWED_USER_IDS=123456789 # Telegram User ID-ul tău
# BTGO
LOGIN_ID=your_btgo_username
PAROLA=your_btgo_password
# SCRAPER
HEADLESS=false # ⚠️ CRITICAL: NU schimba în true!
```
**Cum afli User ID-ul tău:**
```batch
REM După ce ai setat TELEGRAM_BOT_TOKEN în .env
python get_telegram_chat_id.py
REM Trimite un mesaj bot-ului în Telegram
REM Script-ul va afișa User ID-ul
```
---
## 🚀 Pas 3: Deploy Automat
**Right-click pe `deploy.ps1` → "Run with PowerShell" (ca Administrator)**
SAU din PowerShell Administrator:
```powershell
cd deployment\windows\scripts
.\deploy.ps1
```
**Scriptul va instala:**
- ✅ Dependențe Python
- ✅ Playwright browsers
- ✅ Serviciu Windows
- ✅ Auto-start la boot
**Durată:** ~2-3 minute
---
## ✅ Pas 4: Verificare
### 1. Verifică serviciul rulează
```batch
sc query BTGOTelegramBot
```
**Output așteptat:**
```
STATE : 4 RUNNING
```
### 2. Verifică logs
```batch
deployment\windows\scripts\view_logs.bat
```
Sau direct:
```batch
type logs\telegram_bot_stdout.log
```
**Ar trebui să vezi:**
```
[2025-11-06 10:15:23] [INFO] Bot inițializat. Useri autorizați: [123456789]
[2025-11-06 10:15:23] [INFO] Bot pornit. Așteaptă comenzi...
```
### 3. Testează în Telegram
1. Deschide Telegram
2. Caută bot-ul tău (numele setat la @BotFather)
3. Trimite `/start`
**Răspuns așteptat:**
```
🤖 BTGO Scraper Trigger Bot
Comenzi disponibile:
• /scrape - Rulează scraper-ul
• /status - Status sistem
• /help - Ajutor
```
4. Trimite `/scrape` pentru test complet
**Flow 2FA:**
- Bot răspunde: "🤖 BTGO Scraper pornit... Așteaptă 2FA pe telefon!"
- Primești notificare pe telefon în George App
- Aprobi 2FA
- Bot trimite fișierele (solduri + tranzacții CSV)
---
## 🎉 Gata!
Serviciul rulează acum non-stop pe VM. La reboot, pornește automat.
---
## 📋 Comenzi Utile Day-to-Day
### Meniu Interactiv (Cel mai ușor!)
```powershell
# Right-click → "Run with PowerShell" (ca Admin)
deployment\windows\scripts\menu.ps1
```
### Comenzi Directe PowerShell
```powershell
# Status rapid
.\status.ps1
# Restart serviciu (după modificări cod)
.\restart_service.ps1
# View logs live
.\view_logs.ps1
# Oprește serviciu
Stop-Service BTGOTelegramBot
# Pornește serviciu
Start-Service BTGOTelegramBot
# Restart serviciu
Restart-Service BTGOTelegramBot
```
---
## 🔄 Update Cod (după modificări)
```powershell
# Pe VM
cd E:\proiecte\btgo-playwright
git pull
# Restart serviciu (PowerShell)
deployment\windows\scripts\restart_service.ps1
# SAU folosește meniul interactiv
deployment\windows\scripts\menu.ps1
# → Selectează opțiunea 6 (Restart)
```
---
## 🐛 Troubleshooting Rapid
### Serviciul nu pornește
```batch
# Verifică logs
type logs\telegram_bot_stderr.log
```
**Erori comune:**
**"ModuleNotFoundError":**
```batch
python -m pip install -r requirements.txt
deployment\windows\scripts\restart_service.bat
```
**"TELEGRAM_BOT_TOKEN nu este setat":**
- Verifică `.env` există și conține token-ul
- Token-ul trebuie pe o singură linie, fără spații extra
**"Access Denied" în browser:**
- Verifică `HEADLESS=false` în `.env`
- Nu folosi Docker/headless mode
### Bot nu răspunde în Telegram
1. **Verifică serviciul:**
```batch
sc query BTGOTelegramBot
```
2. **Testează manual:**
```batch
REM Oprește serviciul
net stop BTGOTelegramBot
REM Rulează manual pentru debug
python telegram_trigger_bot.py
REM Trimite /start în Telegram
REM Vezi output-ul direct în terminal
```
3. **Verifică firewall:**
- Bot-ul trebuie să acceseze `api.telegram.org` (port 443)
### Scraper-ul timeout-ează la 2FA
În `.env`:
```ini
TIMEOUT_2FA_SECONDS=600 # Crește la 10 minute
```
Apoi restart:
```batch
deployment\windows\scripts\restart_service.bat
```
---
## 📞 Ajutor Suplimentar
- **README complet:** `deployment\windows\README.md`
- **Setup Telegram:** `TELEGRAM_BOT_SETUP.md`
- **Documentație proiect:** `CLAUDE.md`
---
**Enjoy! 🎉**

View File

@@ -0,0 +1,341 @@
# BTGO Telegram Bot - Windows Service Deployment
Scripturi pentru instalarea și gestionarea bot-ului Telegram ca serviciu Windows pe VM.
## 📋 Cerințe Preliminare
- **Windows Server** 2016+ sau **Windows 10/11**
- **Python 3.11+** instalat și adăugat în PATH
- **Privilegii de Administrator**
- **NSSM** (Non-Sucking Service Manager) - se descarcă automat
- **Git** (opțional, pentru pull updates)
## 🚀 Deployment Complet (Recomandat)
```powershell
# Right-click pe script → "Run with PowerShell" (ca Administrator)
deployment\windows\scripts\deploy.ps1
# SAU din PowerShell Administrator:
cd deployment\windows\scripts
.\deploy.ps1
```
**Acest script va:**
1. ✅ Verifica Python și dependențe
2. ✅ Copia și configura `.env` (dacă nu există)
3. ✅ Instala dependențele Python (`requirements.txt`)
4. ✅ Instala browsere Playwright
5. ✅ Instala și porni serviciul Windows
6. ✅ Verifica statusul serviciului
### ⚠️ Înainte de Prima Rulare
**Configurați `.env`** cu datele tale:
```bash
# Telegram Bot
TELEGRAM_BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
TELEGRAM_ALLOWED_USER_IDS=123456789,987654321 # User IDs autorizați
TELEGRAM_CHAT_ID=123456789 # Optional: pentru notificări
# BTGO Credentials
LOGIN_ID=your_btgo_login
PAROLA=your_btgo_password
# Scraper Settings
HEADLESS=false # IMPORTANT: trebuie false pentru VM Windows (WAF bypass)
TIMEOUT_2FA_SECONDS=300
```
**Cum obții variabilele Telegram:**
1. **Bot Token**: Vorbește cu [@BotFather](https://t.me/BotFather) și creează un bot
2. **User IDs**: Rulează `python get_telegram_chat_id.py` după ce configurezi token-ul
## 📦 Scripturi Disponibile
Toate scripturile sunt **PowerShell** (`.ps1`) pentru Windows 10/11.
### `menu.ps1` - Meniu Interactiv ⭐
Interfață user-friendly pentru toate operațiunile.
```powershell
.\menu.ps1
```
---
### `deploy.ps1` - Deployment Complet
Instalează tot ce e necesar și pornește serviciul.
```powershell
.\deploy.ps1
```
---
### `install_service.ps1` - Doar Instalare Serviciu
Instalează serviciul Windows (după ce ai configurat manual tot restul).
```powershell
.\install_service.ps1
```
**Ce face:**
- Descarcă NSSM dacă nu există
- Creează serviciul Windows `BTGOTelegramBot`
- Configurează logging automat în `logs/`
- Configurează auto-restart la crash
- Pornește serviciul
---
### `uninstall_service.ps1` - Dezinstalare Serviciu
Oprește și elimină serviciul din sistem.
```powershell
.\uninstall_service.ps1
```
---
### `restart_service.ps1` - Restart Rapid
Restart rapid al serviciului (pentru aplicarea unor modificări).
```powershell
.\restart_service.ps1
```
---
### `status.ps1` - Status Serviciu
Afișează status detaliat al serviciului și ultimele logs.
```powershell
.\status.ps1
```
---
### `view_logs.ps1` - Viewer Logs Interactiv
Meniu interactiv pentru vizualizarea logs-urilor în timp real.
```powershell
.\view_logs.ps1
```
**Opțiuni:**
1. View stdout (output normal)
2. View stderr (erori)
3. Tail stdout (timp real)
4. Tail stderr (timp real)
5. Deschide Explorer în director logs
6. Șterge toate logurile
---
## 🔧 Gestionare Serviciu
### Comenzi Windows Standard
```batch
# Status serviciu
sc query BTGOTelegramBot
# Oprește serviciu
net stop BTGOTelegramBot
# Pornește serviciu
net start BTGOTelegramBot
# Restart serviciu
net stop BTGOTelegramBot && net start BTGOTelegramBot
# Configurație serviciu
sc qc BTGOTelegramBot
# Șterge serviciu (fără script)
sc delete BTGOTelegramBot
```
### Logs
Logs-urile se salvează automat în `logs/`:
- `telegram_bot_stdout.log` - Output normal (comenzi, mesaje)
- `telegram_bot_stderr.log` - Erori și avertizări
**View logs în PowerShell (timp real):**
```powershell
Get-Content logs\telegram_bot_stdout.log -Wait -Tail 20
```
**Rotație logs:**
- Max 10 MB per fișier
- Rotație automată când se atinge limita
---
## 🔄 Update și Redeploy
### Update Manual (cu Git)
```batch
# Pe VM Windows
cd E:\proiecte\btgo-playwright
# Pull ultimele modificări
git pull origin main
# Redeploy serviciu
deployment\windows\scripts\restart_service.bat
```
### Redeploy Complet (Reinstalare)
Dacă ai modificat dependențe sau structura proiectului:
```batch
# Dezinstalează
deployment\windows\scripts\uninstall_service.bat
# Reinstalează tot
deployment\windows\scripts\deploy.bat
```
---
## 🐛 Troubleshooting
### Serviciul nu pornește
**Verifică logs:**
```batch
deployment\windows\scripts\view_logs.bat
```
**Probleme comune:**
1. **Python nu este în PATH**
- Reinstalează Python cu "Add to PATH" bifat
- Sau setează manual PATH în Environment Variables
2. **`.env` lipsă sau invalid**
- Verifică că `.env` există în root-ul proiectului
- Verifică că `TELEGRAM_BOT_TOKEN` este setat corect
3. **Playwright browser lipsă**
```batch
python -m playwright install chromium
```
4. **Port ocupat / Serviciu duplicat**
```batch
uninstall_service.bat
# Așteaptă 10 secunde
install_service.bat
```
### Bot nu răspunde în Telegram
1. **Verifică serviciul rulează:**
```batch
sc query BTGOTelegramBot
```
2. **Verifică logs pentru erori:**
```batch
type logs\telegram_bot_stderr.log
```
3. **Testează bot-ul manual:**
```batch
python telegram_trigger_bot.py
# Trimite /start în Telegram
# Ctrl+C pentru a opri
```
4. **Verifică firewall:**
- Bot-ul trebuie să poată accesa `api.telegram.org` (HTTPS/443)
### Scraper-ul nu funcționează (Access Denied)
**CRITICAL:** Docker/headless mode NU funcționează din cauza Akamai WAF.
**Soluție:**
- Setează `HEADLESS=false` în `.env`
- Bot-ul TREBUIE să ruleze pe Windows cu browser vizibil
- Asigură-te că VM-ul are desktop environment activ
### Performance Issues
**Bot lent / Scraper timeout:**
- Crește `TIMEOUT_2FA_SECONDS` în `.env`
- Verifică resursele VM-ului (CPU, RAM)
- Verifică conexiunea la internet a VM-ului
---
## 📊 Arhitectura Serviciului
```
BTGOTelegramBot (Windows Service)
├── Managed by: NSSM
├── Auto-start: Yes (Delayed)
├── Restart on crash: Yes (5s delay)
├── Working dir: E:\proiecte\btgo-playwright
├── Python script: telegram_trigger_bot.py
├── Logs: logs\telegram_bot_*.log
└── Config: .env
```
**Flow:**
```
User /scrape → Telegram API → Bot Service → btgo_scraper.py
├── Playwright login
├── 2FA wait
├── Extract accounts
├── Download CSVs
└── Send files via notifiers
```
---
## 🔐 Securitate
### Best Practices
1. **Restricționează accesul bot-ului:**
- Setează `TELEGRAM_ALLOWED_USER_IDS` în `.env`
- Nu lăsa lista goală (permite oricui)
2. **Protejează `.env`:**
- Nu comite `.env` în Git (este în `.gitignore`)
- Setează permisiuni restrictive pe VM
3. **Monitorizează logs-urile:**
- Verifică periodic `stderr.log` pentru erori
- Setup alerting pentru crash-uri
4. **Rotație credentials:**
- Regenerează `TELEGRAM_BOT_TOKEN` periodic
- Update `LOGIN_ID`/`PAROLA` la schimbări
---
## 📞 Support
**Probleme sau întrebări?**
1. Verifică logs: `deployment\windows\scripts\view_logs.bat`
2. Verifică status: `deployment\windows\scripts\status.bat`
3. Consultă documentația principală: `TELEGRAM_BOT_SETUP.md`
4. Check issue tracker: [GitHub Issues](../../../)
---
## 📄 Licență
Acest tool este pentru **uz personal și educațional**. Asigură-te că respecti termenii și condițiile băncii tale.

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)

2
deployment/windows/tools/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
# NSSM binaries (downloaded automatically)
nssm.exe