# FalahOS Sales Automation Scripts

## Setup (One-Time)

### 1. Install dependencies
```bash
cd /Users/wmj24/Desktop/nur-muslim-companion
pip install requests beautifulsoup4 lxml PyJWT
```

### 2. Set environment variables
```bash
# Mautic (web session auth)
export MAUTIC_BASE_URL=https://mautic.falahos.my
export MAUTIC_ADMIN_USER=admin
export MAUTIC_ADMIN_PW=<your-password>

# Gumroad (API access)
export GUMROAD_ACCESS_TOKEN=<from gumroad.com/applications>

# Ghost (Admin API)
export GHOST_ADMIN_API_KEY=<id:secret from ghost.falahos.my/ghost/settings/integrations>
```

### 3. One-time setup (run each once)
```bash
# Create Gumroad products
python scripts/gumroad_setup.py

# Create Mautic segment + emails + import contacts
python scripts/mautic_setup.py

# Verify content queue exists
cat content_queue.json  # should have 10 posts
```

### 4. Install crontab
```bash
crontab scripts/crontab
crontab -l  # verify
```

### 5. Test automation
```bash
python scripts/automation.py
```

## Scripts Reference

| Script | Purpose | When to Run |
|--------|---------|-------------|
| `automation.py` | Main daily automation (mautic, gumroad, ghost, analytics) | Every 6 hours (cron) |
| `mautic_setup.py` | Create segment, import contacts, create 7 emails | One-time |
| `gumroad_setup.py` | Create 3 Gumroad products | One-time |
| `scout_scrape.py` | Scrape 10 new GitHub leads weekly | Sunday (cron) |
| `analytics.py` | Capture daily revenue/order snapshot | Daily (cron) |

## MCP Usage

| MCP | Used By | How |
|-----|---------|-----|
| **scout** | `scout_scrape.py` | Python `sys.path` import → direct function calls |
| **mautic** | `mautic_setup.py`, `automation.py` | Python `sys.path` import → direct function calls |
| **ghost** | `automation.py` | Ghost Admin API (HTTP) |
| **gumroad** | `gumroad_setup.py`, `automation.py` | Gumroad REST API (HTTP) |
| **openhands** | Manual | `npm run build && npm run preview` |

## What's NOT Automated (Manual)

| Task | Why | Frequency |
|------|-----|-----------|
| Social content creation | Requires creative judgment | 3x/day |
| Community engagement (DMs, comments) | Requires human relationship | Daily |
| B2B outreach to 12 quality leads | Requires personal touch | Weekly |
| Product page copywriting | Requires marketing judgment | As needed |
| Strategy review & adjustment | Requires human decision-making | Weekly |

## Monitoring

```bash
# Check daily metrics
tail -1 daily_metrics.jsonl | python -m json.tool

# Check automation logs
tail -f logs/automation.log

# Check content queue remaining posts
python -c "import json; q=json.load(open('content_queue.json')); print(f'{len(q)} posts remaining')"

# Check quality leads count
python -c "import json; l=json.load(open('quality_leads.json')); print(f'{len(l)} leads')"
```