Skip to content

Google Apps Script to sync a City of Toronto recreation drop-in schedule (e.g. lane swim times) to a Google calendar

License

Notifications You must be signed in to change notification settings

tallcoleman/tor-rec-sched-to-cal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Toronto Recreation Schedule to Google Calendar

A Google Apps Script to sync a City of Toronto recreation program schedule (e.g. lane swim times) to your Google calendar.

Installation

  1. Open Google Apps Script at script.google.com and log in to your Google Account if neccessary.

  2. Copy the schedulesync.gs script, paste it into the script editor, and select 'Save'. (You can delete any existing text in the editor.)

  3. 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.

  4. 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.

  5. 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.

  6. 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.)

  7. 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)".

  8. When you reach the permissions screen, select "Allow".

  9. Check to make sure that the script ran correctly and that the events have appeared in your calendar.

  10. 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.

  11. Choose or leave the following trigger settings and then select save. You should be all done!

Trigger Settings

  • 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)

Example Configurations

One schedule, e.g. the regular lane swim at North Toronto Memorial Community Centre:

const programs = [
    {
      'calendar_id': "<example>@group.calendar.google.com",
      'facility_url': "https://www.toronto.ca/data/parks/prd/facilities/complex/189/index.html",
      'program_type': "Swimming",
      'course_title': "Lane Swim",
      'age_info': "",
      'color': ""
    }
  ];

Multiple schedules (can be in the same calendar), e.g. Bridge and Gentle AquaFit at North Toronto Memorial, with AquaFit events coloured "Lavender":

const programs = [
    {
      'calendar_id': "<example>@group.calendar.google.com",
      'facility_url': "https://www.toronto.ca/data/parks/prd/facilities/complex/189/index.html",
      'program_type': "General Interest",
      'course_title': "Cards: Bridge",
      'age_info': "",
      'color': ""
    },
    {
      'calendar_id': "<example>@group.calendar.google.com",
      'facility_url': "https://www.toronto.ca/data/parks/prd/facilities/complex/189/index.html",
      'program_type': "Swimming",
      'course_title': "Aquafit: Gentle",
      'age_info': "",
      'color': "1"
    }
  ];

Beginner Pilates at North Toronto Memorial, but only for ages 16 and older:

const programs = [
    {
      'calendar_id': "<example>@group.calendar.google.com",
      'facility_url': "https://www.toronto.ca/data/parks/prd/facilities/complex/189/index.html",
      'program_type': "Fitness",
      'course_title': "Pilates - Beginner",
      'age_info': "(16yrs and over)",
      'color': ""
    }
  ];

Google Apps Script Permissions (Why does Google say this script is unsafe?)

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 City of Toronto webpages. The script only reads data and does not send any of your data to an external service.

Troubleshooting

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.

Guide to Updated Google Calendar Colors

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:

Property Name Index Documentation Description Actual Color
PALE_BLUE "1" #A4BDFC Pale Blue #7B86C6 Lavender
PALE_GREEN "2" #7AE7BF Pale Green #5DB47E Sage
MAUVE "3" #BDADFF Mauve #832DA4 Grape
PALE_RED "4" #FF887C Pale Red #D88177 Flamingo
YELLOW "5" #FBD75B Yellow #EDC14B Banana
ORANGE "6" #FFB878 Orange #E25D33 Tangerine
CYAN "7" #46D6DB Cyan #4599DF Peacock
GRAY "8" #E1E1E1 Gray #616161 Graphite
BLUE "9" #5484ED Blue #4350AF Blueberry
GREEN "10" #51B749 Green #397E49 Basil
RED "11" #DC2127 Red #C3291C Tomato

About

Google Apps Script to sync a City of Toronto recreation drop-in schedule (e.g. lane swim times) to a Google calendar

Topics

Resources

License

Stars

Watchers

Forks