aboutsummaryrefslogtreecommitdiffstats
path: root/README.md
blob: af9a604e02097b2c85bd0b58c6279a4c6a67c2fa (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# Porkbun Domain Price Checker

A Python CLI tool for bulk querying domain pricing information from the Porkbun API.

## Features

- Bulk domain price queries from a file
- **Domain availability checking** - Shows if domains are available for registration
- JSON Lines output format
- SQLite caching to avoid duplicate API calls
- **Progress bars by default** - Visual feedback for all queries (disable with `-q`)
- Aggressive 429 retry handling
- Async implementation for performance
- Multiple credential sources (CLI, env vars, config file)
- Debug mode with detailed HTTP request/response logging
- Single domain queries with `-d` flag

## Installation

```bash
uv pip install -e .
```

## Configuration

API credentials can be provided in three ways (in order of priority):

### 1. Command Line Arguments
```bash
porkbun test_domains.txt --api-key pk1_... --secret-key sk1_...
```

### 2. Environment Variables
```bash
export PORKBUN_API_KEY=pk1_...
export PORKBUN_SECRET_KEY=sk1_...
porkbun test_domains.txt
```

### 3. Config File
Create `~/.config/porkbun/cli.json`:
```json
{
  "api_key": "pk1_...",
  "secret_key": "sk1_..."
}
```

Then simply run:
```bash
porkbun test_domains.txt
```

## Usage

### Query from File
```bash
# Basic usage (shows progress bars by default)
porkbun test_domains.txt

# Quiet mode (disable progress bars, JSON only)
porkbun test_domains.txt --quiet
porkbun test_domains.txt -q

# Refresh data from API and update cache
porkbun test_domains.txt --refresh

# Clear cache before running
porkbun test_domains.txt --clear-cache

# Debug mode (shows full HTTP requests/responses and status)
porkbun test_domains.txt --debug
```

### Query Single/Multiple Domains
```bash
# Single domain (shows progress bar by default)
porkbun -d example.com
porkbun --domain example.com

# Multiple domains (shows progress for each)
porkbun -d example.com -d test.net -d sample.org

# Quiet mode for clean JSON output (useful for piping)
porkbun -d example.com -q
echo "example.com\ntest.net" | porkbun --quiet

# Combined with other flags
porkbun -d example.com --refresh --debug
```

## Debug Mode

When `--debug` is specified, the tool shows:

1. **Status messages** (to stderr):
   - `[API] Fetching pricing for domain.com...` - When making API calls
   - `[CACHE] Using cached result for domain.com` - When using cached data

2. **Full HTTP details** (to stderr):
   - Complete request headers and payload
   - Complete response headers and body
   - Rate limit retry information

**Example output:**
```bash
$ porkbun -d example.com -d test.net --debug

[API] Fetching pricing for example.com...
================================================================================
DEBUG: REQUEST
URL: POST https://api.porkbun.com/api/json/v3/pricing/get
Headers: {'accept': '*/*', 'accept-encoding': 'gzip, deflate', ...}
Payload: {"apikey": "pk1_...", "secretapikey": "sk1_..."}
================================================================================
DEBUG: RESPONSE
Status: 200 OK
Headers: {'date': '...', 'content-type': 'application/json', ...}
Body: {"status":"SUCCESS","pricing":{...}}
================================================================================
{"domain": "example.com", "tld": "com", "pricing": {"registration": "11.08", ...}}

[CACHE] Using cached result for test.net
{"domain": "test.net", "tld": "net", "pricing": {"registration": "12.52", ...}}
```

**Note:** JSON results always go to stdout, debug/status messages go to stderr for easy separation.

## Progress Bars

**By default**, the tool shows real-time progress bars for each domain being processed. Use `-q` or `--quiet` to disable this for clean JSON-only output.

**Features:**
- Overall progress bar showing total completion
- Individual progress bars for each domain
- Color-coded status indicators:
  - 🟡 Yellow: In progress (checking cache or fetching from API)
  - 🟢 Green: Complete or from cache
  - 🔴 Red: Error occurred
- Shows whether data came from cache or API

**Example output (default):**
```
  Processing domains...      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
  example.com - ✓ From cache ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
  test.net - ✓ Complete      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
  sample.org - ✓ Complete    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
```

**Disable progress bars for piping:**
```bash
# Clean JSON output only (no progress bars)
porkbun domains.txt -q > results.jsonl
porkbun -d example.com --quiet | jq .
```

**When to use quiet mode:**
- Piping output to other tools
- Scripting and automation
- When you only want the JSON output
- Redirecting to files

## Input Format

Create a text file with one domain per line:

```
example.com
google.com
test.net
```

## Output Format

JSON Lines format with pricing and availability information:

```json
{"domain": "example.com", "tld": "com", "pricing": {"registration": "11.08", "renewal": "11.08", "transfer": "11.08", "coupons": []}, "available": false}
{"domain": "myuniquedomain.com", "tld": "com", "pricing": {"registration": "11.08", "renewal": "11.08", "transfer": "11.08", "coupons": []}, "available": true}
```

### Fields:
- `domain` - The queried domain name
- `tld` - Top-level domain (e.g., "com", "net", "org")
- `pricing` - Pricing information from Porkbun
  - `registration` - Price to register the domain
  - `renewal` - Annual renewal price
  - `transfer` - Price to transfer the domain
  - `coupons` - Array of available coupons
- `available` - Boolean indicating if the domain is available for registration at Porkbun
  - `true` - Domain is available
  - `false` - Domain is taken
  - `null` - Availability check failed
- `premium` - (Optional) Set to `true` if domain is premium pricing

## Cache

Pricing and availability data is cached in `~/.local/share/porkbun/cache.sqlite` to avoid redundant API calls and speed up repeated queries.

### Cache Behavior:
- **Default**: Uses cached data when available (fast, no API calls)
- **`--refresh`**: Fetches fresh data from API and updates the cache for queried domains
- **`--clear-cache`**: Deletes all cached data before running

### Example Workflow:
```bash
# First run - queries API and caches results
porkbun -d example.com

# Second run - uses cached data (instant)
porkbun -d example.com

# Update cached data - fetches fresh data and updates cache
porkbun -d example.com --refresh

# Future runs use the updated cache
porkbun -d example.com
```

The cache stores both pricing and availability information, so using `--refresh` is useful when you want to check if previously unavailable domains have become available.