ChatBot / backend /g_cal.py
krishnadhulipalla's picture
updated g-cal
fba3bad
raw
history blame contribute delete
748 Bytes
import os, logging
from pathlib import Path
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
log = logging.getLogger("g_cal")
SCOPES = ["https://www.googleapis.com/auth/calendar.events"]
TOKEN_FILE = Path(os.getenv("GCAL_TOKEN_PATH", "/data/google_token.json"))
def get_gcal_service():
log.info(f"πŸ” get_gcal_service token_path={TOKEN_FILE} exists={TOKEN_FILE.exists()}")
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)
svc = build("calendar", "v3", credentials=creds)
log.info("βœ… built calendar service client")
return svc