#!/usr/bin/env python3
import subprocess
import json
import time
import re

regions = {
    "Hawke's Bay": [
        "packhouse Hastings New Zealand apple",
        "cool storage Napier New Zealand",
        "cold storage Hawke's Bay apple pear"
    ],
    "Bay of Plenty": [
        "packhouse Tauranga kiwifruit",
        "cool storage Te Puke New Zealand",
        "kiwifruit packhouse Bay of Plenty"
    ],
    "Nelson": [
        "packhouse Nelson apple New Zealand",
        "cool storage Motueka orchard",
        "apple packhouse Tasman New Zealand"
    ],
    "Gisborne": [
        "packhouse Gisborne citrus",
        "cool storage Gisborne orchard",
        "citrus packhouse Poverty Bay"
    ],
    "Central Otago": [
        "packhouse Cromwell stonefruit",
        "cool storage Alexandra cherry",
        "orchard packhouse Central Otago"
    ]
}

companies = []

for region, queries in regions.items():
    print(f"\n=== Searching {region} ===")
    
    for query in queries:
        print(f"  Query: {query}")
        
        # Use OpenClaw web search
        result = subprocess.run(
            ['openclaw', 'web-search', query, '--count', '10'],
            capture_output=True,
            text=True
        )
        
        if result.returncode == 0:
            # Parse results - look for company names and websites
            lines = result.stdout.split('\n')
            for line in lines:
                # Very basic extraction - could be improved
                if any(word in line.lower() for word in ['packhouse', 'cool', 'cold', 'storage', 'orchard']):
                    print(f"    Found: {line[:100]}")
        
        time.sleep(2)  # Rate limiting

print("\n✅ Search complete!")
print("Now manually review results and extract companies")
