# VPS Setup Guide for vbvtokenyenile.py

## Linux (Ubuntu/Debian) VPS Requirements

### 1. Install Chrome/Chromium

```bash
# Option 1: Google Chrome (recommended)
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt install ./google-chrome-stable_current_amd64.deb

# Option 2: Chromium
sudo apt-get update
sudo apt-get install -y chromium-browser chromium-chromedriver
```

### 2. Install Python Dependencies

```bash
# Install pip if not available
sudo apt-get install -y python3-pip

# Install required packages
pip3 install selenium-wire selenium
```

### 3. Optional: Install Xvfb (Virtual Display)

If you get display errors, install Xvfb:

```bash
sudo apt-get install -y xvfb

# Start Xvfb
Xvfb :99 -ac &
export DISPLAY=:99
```

### 4. Verify Installation

```bash
# Check Chrome
google-chrome --version
# OR
chromium-browser --version

# Check ChromeDriver
chromedriver --version
```

### 5. Test the Script

```bash
cd /opt/lampp/htdocs/yenicheckbotaerithia/apiler/vbvapi
python3 vbvtokenyenile.py
```

## Common Issues

### Issue: "selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start"

**Solution:**
```bash
# Add Chrome to PATH
export PATH=$PATH:/usr/bin

# Run with explicit chrome path
google-chrome --version
```

### Issue: "selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version..."

**Solution:**
```bash
# Update ChromeDriver to match Chrome version
wget https://chromedriver.storage.googleapis.com/LATEST_RELEASE
CHROMEDRIVER_VERSION=$(cat LATEST_RELEASE)
wget https://chromedriver.storage.googleapis.com/${CHROMEDRIVER_VERSION}/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/bin/chromedriver
sudo chmod +x /usr/bin/chromedriver
```

### Issue: "Message: no such session: target window already closed"

**Solution:** Script is working correctly, browser closed after capturing token. Check `vbvapitoken.txt` file.

## Windows Setup

No special setup needed! Just ensure:
- Chrome browser is installed
- ChromeDriver is in PATH or same directory as script
- Python packages installed: `pip install selenium-wire selenium`

## Testing

### Manual Test (Both Windows & Linux):
```bash
python vbvtokenyenile.py
```

### From Telegram Bot:
Use "VBV API TOKEN YENILE" button in bot's admin menu.

## Success Indicators

✅ Script outputs: `✅ API Token kaydedildi: eyJhbGc...`
✅ File `vbvapitoken.txt` is created/updated with new token
✅ Exit code 0 (success)

## Troubleshooting

Enable debug output:
```bash
python3 vbvtokenyenile.py 2>&1 | tee debug.log
```

Check bot logs:
```bash
tail -f /path/to/bot/logs/bot.log
```
