# Daily Wallpaper Generation
# Automated, lightweight, steerable wallpaper generation

## Overview

Daily generation job creates 1-3 wallpapers per day with:
- **Lightweight** — Small batch size, minimal resource usage
- **Improveable** — Iterative quality improvement through feedback and curation
- **Steerable** — Control by keyword or let it run random, adapt to what works

## Setup

### Cron Job (Linux)

```bash
# Edit crontab
crontab -e

# Add daily job at 9 AM
0 9 * * * /workspace/group/neoncyber/scripts/daily-generation.sh >> /workspace/group/neoncyber/logs/cron.log 2>&1

# Or at midnight
0 0 * * * /workspace/group/neoncyber/scripts/daily-generation.sh
```

### Systemd Timer (Linux)

**Service file:** `/etc/systemd/system/wallpaper-generation.service`
```ini
[Unit]
Description=Daily Wallpaper Generation
After=network-online.target

[Service]
Type=oneshot
WorkingDirectory=/workspace/group/neoncyber
ExecStart=/workspace/group/neoncyber/scripts/daily-generation.sh
User=YOUR_USER
Environment=PATH=/usr/local/bin:/usr/bin:/bin
Environment=CF_API_TOKEN=YOUR_TOKEN
Environment=CF_ACCOUNT_ID=YOUR_ACCOUNT_ID
```

**Timer file:** `/etc/systemd/system/wallpaper-generation.timer`
```ini
[Unit]
Description=Daily Wallpaper Generation Timer
Requires=wallpaper-generation.service

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target
```

**Enable:**
```bash
sudo systemctl enable wallpaper-generation.timer
sudo systemctl start wallpaper-generation.timer
```

## Usage

### Automatic (Cron/Systemd)
Runs daily at configured time. Random theme selected automatically.

### Manual
```bash
# Random theme (default)
bash /workspace/group/neoncyber/scripts/daily-generation.sh

# Specific keyword
bash /workspace/group/neoncyber/scripts/daily-generation.sh geometry
bash /workspace/group/neoncyber/scripts/daily-generation.sh atmosphere
bash /workspace/group/neoncyber/scripts/daily-generation.sh glitch
```

### Keywords

- `random` — (default) Random theme selection
- `geometry` — Impossible geometric forms
- `atmosphere` — Atmospheric cyberpunk scenes
- `surreal` — Surreal objects and dream logic
- `minimal` — Minimal silhouettes and clean lines
- `glitch` — Digital corruption and pixel sorting

## Output

**Directory:** `/workspace/group/neoncyber/renders/YYYYMMDD/`

**Log:** `/workspace/group/neoncyber/logs/generation-YYYYMMDD.log`

**Notification:** Optional webhook for status updates

### Example Log

```
[2026-06-13 09:00:00] Checking Cloudflare availability...
[2026-06-13 09:00:01] ✅ Cloudflare available. Starting daily generation...
[2026-06-13 09:00:01] 📅 Daily Generation Job: 20260613
[2026-06-13 09:00:01] 🎯 Keyword: random
[2026-06-13 09:00:01] 🎲 Selected theme: geometry
[2026-06-13 09:00:01] Generating: daily_geo_klein
[2026-06-13 09:00:30] ✅ Daily generation complete!
[2026-06-13 09:00:30] 📊 Generated: 1 wallpapers
[2026-06-13 09:00:30] 🔄 Next run: Tomorrow (2026-06-14)
```

## Features

### Cloudflare Limit Detection
- Checks API availability before generation
- Skips if daily limit reached
- Logs status and retries tomorrow
- Sends notification if configured

### Theme Selection
- 5 theme categories for variety
- Random selection each day
- Steerable by keyword
- Each theme has curated prompts

### Logging
- Timestamped logs for each run
- Output directory and file tracking
- Cloudflare status monitoring
- Generation count

### Notifications (Optional)
```bash
export WEBHOOK_URL="your_webhook_url"
```

## Steerable Generation

### Weekday Themes
```bash
# Monday: Geometry
0 9 * * 1 /workspace/group/neoncyber/scripts/daily-generation.sh geometry

# Tuesday: Atmosphere
0 9 * * 2 /workspace/group/neoncyber/scripts/daily-generation.sh atmosphere

# Wednesday: Surreal
0 9 * * 3 /workspace/group/neoncyber/scripts/daily-generation.sh surreal

# Thursday: Minimal
0 9 * * 4 /workspace/group/neoncyber/scripts/daily-generation.sh minimal

# Friday: Glitch
0 9 * * 5 /workspace/group/neoncyber/scripts/daily-generation.sh glitch

# Weekend: Random
0 9 * * 6,0 /workspace/group/neoncyber/scripts/daily-generation.sh random
```

### Custom Schedule
```bash
# Every 6 hours (4x daily)
0 */6 * * * /workspace/group/neoncyber/scripts/daily-generation.sh

# Twice daily (9 AM and 9 PM)
0 9,21 * * * /workspace/group/neoncyber/scripts/daily-generation.sh

# Weekly (Sundays at midnight)
0 0 * * 0 /workspace/group/neoncyber/scripts/daily-generation.sh
```

## Environment Variables

Required:
- `CF_API_TOKEN` — Cloudflare API token
- `CF_ACCOUNT_ID` — Cloudflare account ID

Optional:
- `WEBHOOK_URL` — Notification webhook URL
- `LOG_LEVEL` — Logging verbosity (default: info)

## Monitoring

### Check logs
```bash
# Today's log
cat /workspace/group/neoncyber/logs/generation-$(date +%Y%m%d).log

# Last 7 days
find /workspace/group/neoncyber/logs/ -name "generation-*.log" -mtime -7 -exec cat {} \;

### Check generated files
```bash
# Today's renders
ls -la /workspace/group/neoncyber/renders/$(date +%Y%m%d)/

# This week's renders
find /workspace/group/neoncyber/renders/ -name "*.jpg" -mtime -7
```

### Stats
```bash
# Total this month
find /workspace/group/neoncyber/renders/ -name "*.jpg" -mtime -30 | wc -l
```

## Troubleshooting

### Cloudflare Limit Reached
**Error:** `429 daily limit exceeded`

**Solution:**
- Wait for reset (~24 hours from last generation)
- Consider upgrading Cloudflare plan
- Reduce generation frequency

### Cron Not Running
**Check:** `crontab -l`

**Test:** `bash /workspace/group/neoncyber/scripts/daily-generation.sh`

### Missing Environment Variables
**Error:** `CF_API_TOKEN env var required`

**Solution:** Export in crontab or systemd service:
```bash
export CF_API_TOKEN=your_token
export CF_ACCOUNT_ID=your_account_id
```

## Growth Projection

**Daily (1/day):** 365 wallpapers/year
**Weekdaily (5/week):** 260 wallpapers/year
**Twice daily (2/day):** 730 wallpapers/year

At 1/day:
- Month 1: 30 wallpapers
- Month 6: 180 wallpapers
- Month 12: 365 wallpapers

Perfect for steady portfolio growth without overwhelming curation.

## Next Steps

1. Set up cron or systemd timer
2. Configure webhook notifications (optional)
3. Run manual test: `bash daily-generation.sh`
4. Monitor first few days
5. Adjust schedule if needed
6. Curate weekly via gallery dashboard
