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

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

# Load Non Cool Rooms data
with open('/Users/max/.openclaw/workspace/postharvest/non-cool-rooms.json', 'r') as f:
    data = json.load(f)
    rows = data['values']

header = rows[0]
print(f"Current rows: {len(rows)-1}")

# Filter out Apple retail stores
filtered = [header]
deleted_count = 0

for row in rows[1:]:
    company_name = (row[0] if len(row) > 0 else '').strip()
    
    # Check if it's an Apple retail store
    if company_name.startswith('Apple ') and not any(x in company_name.lower() for x in ['orchard', 'farm', 'packing', 'storage', 'cold']):
        print(f"Deleting: {company_name}")
        deleted_count += 1
    else:
        filtered.append(row)

print(f"\nDeleted {deleted_count} Apple retail stores")
print(f"Remaining rows: {len(filtered)-1}")

# Update sheet
print("\nUpdating 'Non Cool Rooms' sheet...")

subprocess.run([
    'gog', 'sheets', 'clear',
    spreadsheet_id,
    'Non Cool Rooms!A:Z',
    '--account', account
], capture_output=True)

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

if result.returncode == 0:
    print(f"✅ Deleted {deleted_count} Apple retail stores")
else:
    print(f"❌ Error: {result.stderr}")
