Give your AI agent "eyes" to see your schedule and automate daily briefings.
Objective: Connect a Python-based AI agent to your Google Calendar using a secure, read-only feed, and schedule it to run automatically.
Prerequisite: Google Account, VS Code, Python installed.
To let an agent read your calendar without giving it full password access, we use the "Secret Address in iCal format." This is a read-only door to your schedule.
.ics).Now we will write a Python script that uses this URL to check your day.
Open your terminal and install the requests and icalendar libraries:
pip install requests icalendar pytz
Create a file named check_calendar.py and paste the following code. replace YOUR_ICAL_URL_HERE with the URL you copied.
import requests
from icalendar import Calendar
from datetime import datetime, timedelta
import pytz
# CONFIGURATION
ICAL_URL = "YOUR_ICAL_URL_HERE"
MY_TIMEZONE = pytz.timezone('America/New_York') # Change to your timezone
def get_todays_events():
print("ā³ Fetching calendar...")
try:
response = requests.get(ICAL_URL)
response.raise_for_status()
cal = Calendar.from_ical(response.content)
except Exception as e:
print(f"ā Error fetching calendar: {e}")
return
today = datetime.now(MY_TIMEZONE).date()
print(f"\nš
Events for {today}:")
found_event = False
for component in cal.walk():
if component.name == "VEVENT":
start = component.get('dtstart')
summary = component.get('summary')
# Handle different date types (all-day vs specific time)
if hasattr(start.dt, 'date'):
event_date = start.dt.date()
else:
event_date = start.dt
if event_date == today:
found_event = True
# Format time if valid
if hasattr(start.dt, 'strftime'):
time_str = start.dt.astimezone(MY_TIMEZONE).strftime("%I:%M %p")
else:
time_str = "All Day"
print(f" - [{time_str}] {summary}")
if not found_event:
print("ā
No events found for today!")
if __name__ == "__main__":
get_todays_events()
Run the script in your terminal:
python check_calendar.py
An agent isn't useful if you have to manually run it. Let's schedule it to run every morning automatically.
Windows has a built-in tool called Task Scheduler.
Win + S and search for Task Scheduler.python (or the full path to python.exe)."C:\Users\You\check_calendar.py").Pro Tip: To run this in the background, use "Create Task" instead and select "Run whether user is logged on or not".
On macOS, the terminal tool cron is the standard for scheduling.
crontab -e (this opens the edit mode).i to insert text.0 8 * * * /usr/bin/python3 /Users/yourname/check_calendar.py >> /tmp/calendar.log 2>&1
Esc, then type :wq and hit Enter to save.This tells the system: "At minute 0 of hour 8, every day, run python3 on this file."