A Google Apps Script to sync a City of Toronto recreation program schedule (e.g. lane swim times) to your Google calendar.
This script uses Open Data from the City of Toronto, specifically the "Facilities" and "Drop-In" datasets from https://open.toronto.ca/dataset/registered-programs-and-drop-in-courses-offering/.
-
Open Google Apps Script at script.google.com and log in to your Google Account if neccessary.
-
Copy the schedulesync.gs script, paste it into the script editor, and select 'Save'. (You can delete any existing text in the editor.)
-
At this point, it is also a good idea to rename the script project from 'Untitled project' to something like "Toronto Rec Schedule Sync". You can rename the project by selecting its name at the top of your screen.
-
Fill out the config details below where it says
const programs = [
. There are instructions in the script and samples below for additional help. I also strongly recommend creating a separate calendar for the script so that you avoid creating any problems with the main calendar in your account. -
To the right of the icon is a function drop-down (it will probably say 'updateSchedules'). Open this drop-down, select 'updateSchedules', and then select 'Run'. This will sync your selected schedule(s) to your calendar for the first time.
-
Since this is the first time you are using the script, it will ask you for permissions. (If you are unfamiliar with Google Apps Script permissions, you can read a short explainer below.)
-
After selecting "Continue", you may come to a screen that says "Google hasn't verified this app". If you are presented with this screen, select "Advanced" at the bottom-left and then "Go to Untitled project (unsafe)".
-
When you reach the permissions screen, select "Allow".
-
Check to make sure that the script ran correctly and that the events have appeared in your calendar.
-
In order to run the script every week, you will have to set up a trigger. In the menu to the left, select the alarm clock icon to go to the Triggers menu. Select "Add Trigger" at the bottom-right.
-
Choose or leave the following trigger settings and then select save. You should be all done!
- Which function to run: updateSchedules
- Which deployment to run: Head
- Event source: Time-driven
- Type of time based trigger: Week timer
- Day of week: Every Monday (or your choice)
- Time of Day: Midnight to 1am (or your choice)
- Failure notification settings: Notify me immediately (or your choice)
For all of these:
- The number for locationID can be found at the very end of the webpage URL
- The value for calendarID can be found in the "Integrate calendar" section of your Google Calendar settings
- userAge is optional and helps to select programs within a relevant age range
- color is also optional
One schedule, e.g. the regular lane swim at North Toronto Memorial Community Centre:
const programs = [
{
locationID: 189,
courseTitle: "Lane Swim",
calendarID: "[email protected]",
userAge: 40,
},
];
Multiple schedules (can be in the same calendar), e.g. Bridge and Gentle AquaFit at North Toronto Memorial, with AquaFit events coloured "Peacock":
const programs = [
{
locationID: 189,
courseTitle: "Cards: Bridge",
calendarID: "[email protected]",
userAge: 40,
},
{
locationID: 189,
courseTitle: "Aquafit: Gentle",
calendarID: "[email protected]",
userAge: 40,
color: "Peacock", // other values to get this color: "1", "Pale Blue"
},
];
Pilates at North Toronto Memorial, including the programs for ages 60 and older:
const programs = [
{
locationID: 189,
courseTitle: "Pilates",
calendarID: "[email protected]",
userAge: 65,
},
];
Google Apps use the same security system for scripts that you write (or copy in) yourself and add-ons created by third parties. The permissions system is therefore designed to be very cautious so that users do not give third parties unintended permissions for their Google Account.
The permissions used by the script are required for the following reasons:
See, edit, share, and permanently delete all the calendars you can access using Google Calendar
This permission is required for the script to add and update events in your calendar. The script will not share your calendar or delete any events other than the ones it keeps updated.
Connect to an external service
This permission is required for the script to read the City of Toronto open data API. The script only reads data and does not send any of your data to an external service.
If you have any problems or questions while using the script, please open a new issue in the "Issues" tab of this repository.
If you want to delete all the events in a specific calendar so that you can run the script from scratch, see the instructions for the clearCalendar
function at the bottom of schedulesync.gs.
The documentation for the EventColor Enum appears to be out of date. The actual colors you will get from the following Enums/Indexes are as follows: