# backend/gcal.py import os from pathlib import Path from google.oauth2.credentials import Credentials from googleapiclient.discovery import build # Same scope you used everywhere SCOPES = ["https://www.googleapis.com/auth/calendar.events"] # HF Spaces persistent disk path (Settings → Persistent storage) TOKEN_FILE = Path(os.getenv("GCAL_TOKEN_PATH", "/data/google_token.json")) def get_gcal_service(): """ Load saved Google OAuth credentials and return a Calendar API client. Raise a clear error if not connected yet. """ if not TOKEN_FILE.exists(): raise RuntimeError("Google Calendar not connected. Visit /oauth/google/start to connect.") creds = Credentials.from_authorized_user_file(str(TOKEN_FILE), SCOPES) return build("calendar", "v3", credentials=creds)