# PinScrape CLI Documentation

## Daftar Isi

- [Interactive Menu (run.bat)](#interactive-menu-runbat)
- [Python CLI (scripts/cli.py)](#python-cli-scriptsclipy)
- [Go Exporter (go/exporter.exe)](#go-exporter-goexporterexe)
- [PHP Exporter (php/exporter.php)](#php-exporter-phpexporterphp)
- [Standalone Scripts](#standalone-scripts)
- [Batch File Shortcuts](#batch-file-shortcuts)
- [Templates](#templates)
- [Full Pipeline Example](#full-pipeline-example)

---

## Interactive Menu (run.bat)

Jalankan menu interaktif dengan:

```bash
run.bat
```

```
=============================
   PinScrape CLI
=============================
 1. Convert Keywords
 2. Scrape Images
 3. Generate AI Titles
 4. Generate AI Articles
 5. Full Workflow (Scrape + AI Title + AI Article)
 6. Export (PHP)
 7. Export (Go - Fast)
 8. Create & Upload
 9. Submit
10. Export (Go) + Create & Upload + Submit
11. Clean AI Titles
12. Delete AI Content
13. Exit
=============================
```

---

## Python CLI (scripts/cli.py)

Entry point utama untuk semua perintah Python. Syntax:

```bash
python scripts/cli.py <command> [options]
```

### Commands

#### `convert` — Konversi keyword ke database

Mengubah file `.txt` di folder `keywords/` menjadi database SQLite di folder `database/`.

```bash
python scripts/cli.py convert
```

#### `scrape` — Scrape gambar dari Pinterest

Melakukan scraping gambar dari Pinterest untuk semua keyword yang belum di-scrape.

```bash
python scripts/cli.py scrape
```

#### `ai title` — Generate AI titles

Menghasilkan judul artikel menggunakan AI untuk semua post yang belum memiliki `ai_title`.

```bash
python scripts/cli.py ai title
```

#### `ai article` — Generate AI articles

Menghasilkan konten artikel menggunakan AI untuk semua post yang belum memiliki `ai_content`.

```bash
python scripts/cli.py ai article
```

#### `workflow` — Full workflow

Menjalankan pipeline lengkap: scrape → AI title → AI article secara berurutan.

```bash
python scripts/cli.py workflow
```

#### `export` — Export artikel ke HTML (PHP)

Export database ke file HTML menggunakan PHP exporter. Mode interaktif (prompt split size & template).

```bash
python scripts/cli.py export
```

#### `deploy` — Buat bucket & upload ke GCS

Membuat Google Cloud Storage bucket dan mengupload hasil export.

```bash
python scripts/cli.py deploy
python scripts/cli.py deploy --auto    # skip konfirmasi
```

#### `submit` — Submit ke IndexNow

Mengirim URL ke search engine melalui IndexNow API.

```bash
python scripts/cli.py submit
python scripts/cli.py submit --auto    # skip konfirmasi
```

#### `full-deploy` — Export + Deploy + Submit

Pipeline lengkap: generate CREATE.csv → export HTML → deploy ke GCS → submit IndexNow → generate report.

```bash
python scripts/cli.py full-deploy
```

#### `full-deploy-report` — Print summary & generate CSV report

Menampilkan ringkasan deploy dan menghasilkan file CSV report di folder `report/`.

```bash
python scripts/cli.py full-deploy-report
```

#### `full-deploy-generate` — Generate CREATE.csv

Membuat file `CREATE.csv` yang memetakan bucket ke folder.

```bash
python scripts/cli.py full-deploy-generate
python scripts/cli.py full-deploy-generate 5000    # dengan split_size
```

#### `clean-title` — Bersihkan tanda kutip dari AI titles

Menghapus karakter kutip (`"`, `"`, `"`) dari semua `ai_title` di database.

```bash
python scripts/cli.py clean-title
```

#### `delete-ai` — Hapus semua AI content

Menghapus semua `ai_title` dan `ai_content` dari seluruh database (dengan konfirmasi).

```bash
python scripts/cli.py delete-ai
```

---

## Go Exporter (go/exporter.exe)

Exporter HTML berbasis Go yang lebih cepat. Bisa dijalankan secara interaktif maupun non-interaktif.

### Flags

| Flag | Deskripsi |
|---|---|
| `--split-size <int>` | Jumlah artikel per subfolder |
| `--template <name\|num>` | Nama template atau nomor urut (1-based) |
| `--create-csv <path>` | Path ke CREATE.csv (default: `CREATE.csv`) |
| `--workers <int>` | Jumlah parallel workers |
| `--interactive` | Mode interaktif dengan prompt |
| `--list-templates` | Tampilkan daftar template dan keluar |

### Contoh

```bash
# Mode interaktif
go\exporter.exe --interactive

# Non-interaktif dengan parameter lengkap
go\exporter.exe --split-size=5000 --template=glassmorphism --workers=4

# Gunakan nomor template (urutan dari --list-templates)
go\exporter.exe --split-size=5000 --template=12 --workers=4

# Lihat daftar template
go\exporter.exe --list-templates

# Build dari source (jika .exe belum ada)
cd go && go build -o exporter.exe . && cd ..
```

---

## PHP Exporter (php/exporter.php)

Exporter HTML berbasis PHP. Dipanggil oleh `python scripts/cli.py export`.

### Options

| Option | Deskripsi |
|---|---|
| `--split-size=<int>` | Jumlah artikel per subfolder |
| `--template=<name>` | Nama template (contoh: `modern`, `glassmorphism`) |
| `--create-csv=<path>` | Path ke CREATE.csv (default: `CREATE.csv`) |
| `--workers=<int>` | Jumlah parallel workers |

### Contoh

```bash
php php\exporter.php --split-size=5000 --template=modern --workers=4
php php\exporter.php --split-size=3000 --template=cyberpunk --workers=2
```

---

## Standalone Scripts

Script-script ini bisa dijalankan secara independen tanpa melalui `cli.py`.

### scripts/deploy.py

```bash
python scripts/deploy.py [options]
```

| Option | Default | Deskripsi |
|---|---|---|
| `--create-csv` | `CREATE.csv` | Path ke CREATE.csv |
| `--location` | `us-central1` | Lokasi GCS bucket |
| `--concurrency` | `3` | Max operasi paralel |
| `--export-folder` | `export/` | Path folder export |

Contoh:
```bash
python scripts/deploy.py --create-csv=CREATE.csv --location=us-central1 --concurrency=5
```

### scripts/submit_now.py

```bash
python scripts/submit_now.py [options]
```

| Option | Default | Deskripsi |
|---|---|---|
| `--create-csv` | `CREATE.csv` | Path ke CREATE.csv |
| `--export-folder` | `export/` | Path folder export |

Contoh:
```bash
python scripts/submit_now.py --create-csv=CREATE.csv --export-folder=export
```

### scripts/ai_generator.py

```bash
python scripts/ai_generator.py <title|article>
```

Contoh:
```bash
python scripts/ai_generator.py title
python scripts/ai_generator.py article
```

### scripts/check_db.py

Mengecek status database (jumlah post, gambar, title, article).

```bash
python scripts/check_db.py
```

### scripts/cleaning_title.py

Membersihkan tanda kutip dari AI title.

```bash
python scripts/cleaning_title.py
```

### scripts/delete_ai_content.py

Menghapus semua AI title dan AI content.

```bash
python scripts/delete_ai_content.py
```

### scripts/convert.py

Mengkonversi file keyword `.txt` ke database SQLite.

```bash
python scripts/convert.py
```

### scripts/generate_create_csv.py

Membuat file `CREATE.csv`.

```bash
python scripts/generate_create_csv.py [split_size]
```

---

## Batch File Shortcuts

| File | Fungsi |
|---|---|
| `1. INSTALL JALAN AWAL SEKALI SAJA.bat` | Install dependencies (`pip install -r requirements.txt`) |
| `run.bat` | Buka menu interaktif utama |
| `check_db.bat` | Jalankan `scripts/check_db.py` |
| `CLEANING_TITLE.bat` | Jalankan `scripts/cleaning_title.py` |
| `DELETE AI CONTENT.bat` | Jalankan `scripts/delete_ai_content.py` |

---

## Templates

Tersedia 24 template HTML (format `.php` dan `.gohtml`):

| No | Nama Template |
|---|---|
| 1 | aurora |
| 2 | bento |
| 3 | brutalist |
| 4 | classic-magazine |
| 5 | crimson |
| 6 | cyberpunk |
| 7 | dark-stone |
| 8 | dev-docs |
| 9 | flat-modern |
| 10 | gallery |
| 11 | generatepress-orange |
| 12 | glassmorphism |
| 13 | high-contrast |
| 14 | modern |
| 15 | monochrome |
| 16 | ocean |
| 17 | pinterest |
| 18 | premium-magazine |
| 19 | sky-blue |
| 20 | sunset |
| 21 | vivid-contrast |

Template `article`, `layout`, dan `index` adalah template struktural dan tidak ditampilkan dalam pilihan.

Default template di `config.json`: **glassmorphism**

---

## Full Pipeline Example

Contoh menjalankan pipeline lengkap dari awal hingga akhir:

```bash
# 1. Install dependencies (pertama kali saja)
pip install -r requirements.txt

# 2. Konversi keyword ke database
python scripts/cli.py convert

# 3. Scrape gambar dari Pinterest
python scripts/cli.py scrape

# 4. Generate AI titles
python scripts/cli.py ai title

# 5. Generate AI articles
python scripts/cli.py ai article

# 6. Export ke HTML (pilih salah satu)
python scripts/cli.py export                          # PHP (interaktif)
go\exporter.exe --split-size=5000 --template=12 --workers=4  # Go (non-interaktif)

# 7. Deploy ke Google Cloud Storage
python scripts/cli.py deploy

# 8. Submit ke IndexNow
python scripts/cli.py submit

# Atau jalankan semuanya sekaligus:
python scripts/cli.py workflow       # step 3-5
python scripts/cli.py full-deploy    # step 6-8 + report
```

### Full Pipeline via Menu Interaktif

```bash
run.bat
# Pilih menu 10: Export (Go) + Create & Upload + Submit
```

---

## config.json

Konfigurasi utama yang mempengaruhi behavior CLI:

```json
{
    "split_size": 5000,
    "worker_count": 4,
    "template": "glassmorphism",
    "export_folder": "export",
    "data_folder": "database",
    "inject_folder": "inject",
    "concurrency": 30,
    "image_result": 26,
    "ai": {
        "base_url": "https://openrouter.ai/api/v1",
        "api_key": "APIKEY",
        "model": "inclusionai/ling-2.6-flash",
        "concurrency": 50
    }
}
```
