Google Calendar programmatic event listing and bulk insert made easy

Antonio Val
2 min readSep 20, 2017

--

gcal is a command line tool running in Node.js that allows event listing, insert or bulk insert through the Google Calendar API.

List events:

It will list today events if executed without arguments:

$ gcal list

The format of the response is customizable, but this is the default one:

Upcoming events (2017-09-07T00:00:00+09:00 ~ 2017-09-07T23:59:59+09:00)
2017-09-07 20:00 - My favorite TV show
2017-09-07 22:30 - Prepare tomorrow's meeting stuff

Also, natural language can be used to set the term:

$ gcal list yesterday$ gcal list 'from tomorrow to the day after tomorrow'$ gcal list 'since yesterday until next week'

Specific ISO dates can be specified as well:

$ gcal list -f 2017-03-23 -t 2017-03-27

Insert an event

Also insertion can be done using natural language:

$ gcal insert 'Party tomorrow from 3pm to 5pm'

Insert events specifying the parameters:

$ gcal insert -s 'Party' -d 2017-03-23 -t 15:00 -D 2h

Bulk insert

Create a .json file with the following format:

$ echo \
'[{
"calendarId": "primary", "resource": {
"summary": "Party",
"start": { "dateTime": "2017-09-08T20:00" },
"end": { "dateTime": "2017-09-08T22:00" }}
},{
"calendarId": "primary", "resource": {
"summary": "Party again",
"start": { "dateTime": "2017-09-08T22:00" },
"end": { "dateTime": "2017-09-08T23:30" }}
}]' \
> events.json

And pass it as argument to do a bulk insert:

$ gcal bulk -e events.json

A .js file is also accepted as well, useful for relative dates and more:

// events.js
const today = new Date();
today.setHours('17', '00', '00');
const tomorrow = new Date(today.getTime()+1000*60*60*24);
module.exports = [{
"calendarId": "primary",
"resource": {
"summary": `Release`,
"start": {
"dateTime": today.toISOString()
},
"end": {
"dateTime": today.toISOString()
}
}
}, {
"calendarId": "primary",
"resource": {
"summary": "Release",
"start": {
"dateTime": tomorrow.toISOString()
},
"end": {
"dateTime": tomorrow.toISOString()
}
}
}];

$ gcal bulk -e ./events.js

( The available properties are listed here).

Some use cases

Some use cases include scripting/automation, like using it in your continuous integration workflow (e.g., insert an event in the calendar after a production release).

…Or just for people who live in the terminal.

About authentication and custom configuration

Authorization and authentication is done with OAuth 2.0, preparing your credentials will only take around 2 minutes.

Also the default config can be overridden using a config file.

For more info check the README of the repo. Any feedback is appreciated!

--

--