def get_events_for_date(target_date=None, use_api=True): """ Fetches events for a specific date from Google Calendar. Tries API first (if use_api=True), falls back to ICS if API fails. Args: target_date: datetime.date object for the target day. If None, uses today. use_api: If True, try Google Calendar API first. If False, use ICS only. Returns: List of event dictionaries. """ if use_api and GCAL_API_AVAILABLE: print("[GCal] Attempting to use Google Calendar API...") try: events = get_events_for_date_api(target_date) if events is not None: print(f"[GCal] Successfully fetched {len(events)} events via API") return events else: print("[GCal] API returned None. Falling back to ICS...") except Exception as e: print(f"[GCal] API failed with error: {e}") print("[GCal] Falling back to ICS...") # Fallback to ICS print("[GCal] Using ICS feed method...") return get_events_for_date_ics(target_date)