Working with Google Calendar

Working examples of Python code used to interact with Google Calendar.

C05348A3-9AB8-42C9-A6E0-81DB3AC59FEB
           

Getting Started

The Google Calendar has always been a great utility, with its easy-to-use interface and the ability to share calendars. You may not be aware that there is also a great Python library to interact with your calendar.

Getting started with the library is still not as straightforward as it should be, you may run into some library issues, and I personally still find their permission model and getting credential tokens very confusing. But once you get past this hurdle, using the library is very easy. Getting recurring events via the API has also gotten much easier than it used to be.

Working Examples

This GitHub Repository includes a few practical examples to read and write events to the calendar.

The Calendar Reminders example is quite useful, it goes through a given number of upcoming events and ensures that the proper reminders are set so that you get the wanted notifications and don't miss your event.

The Add Work Holidays example shows a way to bulk-create events based on a list of dates in plaintext.

The Add Flight Info is also quite useful, given a travel itinerary in .yaml format, it will create entries in a Google Calendar with departure and arrival times in local timezones. This avoids doing some fancy timezone conversions when you do a lot of international travel. Google and Apple both handle this automatically from your email (talk about privacy!), but this is a great alternative when this doesn't happen by itself.

Finally, one of the most complex examples, ISS Visible is used to determine the optimal viewing times from the ISS (code name ZARYA) in the next 10 days between sunset and 10:30 pm. The code creates calendar events if they don't already exist. You may not be that interested in the ISS, but the code to compare if an event already exists can be useful.

It would also be trivial to create an example to announce events using Google Text-to-Speech, a feature that I wish both Google Home and Alexa would have out of the box but might be a good use of a Raspberry Pi.

Hope you'll find these useful, and happy coding!

Posted Comments: 0

Tagged with:
Calendar