import json
from google.oauth2 import service_account
from googleapiclient.discovery import build

# Đường dẫn key anh đã cập nhật
SERVICE_ACCOUNT_FILE = '/opt/openclaw/config/workspace/google_service_account.json'
SPREADSHEET_ID = '15YIFXJLkMJEqHFCWbguADNCzqEiZkX7k9Bo7WrBP43w'

def update_sheet():
    try:
        creds = service_account.Credentials.from_service_account_file(
            SERVICE_ACCOUNT_FILE, scopes=['https://www.googleapis.com/auth/spreadsheets'])
        service = build('sheets', 'v4', credentials=creds)
        
        range_name = 'Sheet1!A1'
        body = {'values': [['Hello from OpenClaw (test edit) - Updated by Zen']]}
        
        result = service.spreadsheets().values().update(
            spreadsheetId=SPREADSHEET_ID, range=range_name,
            valueInputOption='RAW', body=body).execute()
            
        print(f"Thành công! Đã chèn vào {result.get('updatedCells')} ô.")
    except Exception as e:
        print(f"Lỗi: {e}")

if __name__ == '__main__':
    update_sheet()
