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

spreadsheet_id = '1uVd-xZFF4TEQGqtvw9z6W8fffeaifPCoLsek83GmEoQ'
account = 'jonny@jonnyshannon.com'

# Load current data
with open('/Users/max/.openclaw/workspace/postharvest/nz-current.json', 'r') as f:
    data = json.load(f)
    rows = data['values']

header = rows[0]
filtered = [header]

# Delete Golden Oak Orchard (verified small)
deleted = []
for row in rows[1:]:
    if len(row) == 0:
        continue
    
    company_name = row[0]
    
    if company_name == 'Golden Oak Orchard':
        print(f"Deleting: {company_name} (verified small local orchard)")
        deleted.append(company_name)
    else:
        filtered.append(row)

print(f"\nDeleted {len(deleted)} companies")
print(f"Remaining: {len(filtered)-1} companies")

# Update sheet
subprocess.run([
    'gog', 'sheets', 'clear',
    spreadsheet_id,
    'New Zealand!A:O',
    '--account', account
], capture_output=True)

result = subprocess.run([
    'gog', 'sheets', 'update',
    spreadsheet_id,
    'New Zealand!A1',
    '--values-json', json.dumps(filtered),
    '--input', 'USER_ENTERED',
    '--account', account
], capture_output=True, text=True)

if result.returncode == 0:
    print(f"✅ Deleted Golden Oak Orchard")
else:
    print(f"❌ Error: {result.stderr}")
