#!/bin/bash
# Combined email + calendar scan using gws CLI — both accounts
# kitt@curiousendeavor.com (gws-auth default) + assafdagancos@gmail.com (personal token)
cd /root/.openclaw/workspace

echo "## 📬 kitt@curiousendeavor.com"
gws-auth gmail +triage --format table 2>&1

echo ""
echo "## 📬 assafdagancos@gmail.com"
source venv/bin/activate
FRESH_TOKEN=$(python3 -c "
import json
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
with open('google-auth/token-personal.json') as f:
    d = json.load(f)
creds = Credentials(
    token=d.get('access_token'),
    refresh_token=d.get('refresh_token'),
    token_uri='https://oauth2.googleapis.com/token',
    client_id=d['client_id'],
    client_secret=d['client_secret'],
)
creds.refresh(Request())
print(creds.token)
" 2>&1)
GOOGLE_WORKSPACE_CLI_TOKEN="$FRESH_TOKEN" gws gmail +triage --format table 2>&1

echo ""
echo "## 📅 Calendar — kitt@"
gws-auth calendar +agenda --today --format table 2>&1

echo ""
echo "## 📅 Calendar — personal"
GOOGLE_WORKSPACE_CLI_TOKEN="$FRESH_TOKEN" gws calendar +agenda --today --format table 2>&1
