Skip to content

Instantly share code, notes, and snippets.

@Tolsee
Created August 9, 2018 04:43
Show Gist options
  • Save Tolsee/6efcff33f6b7cba324e9eafabf120caf to your computer and use it in GitHub Desktop.
Save Tolsee/6efcff33f6b7cba324e9eafabf120caf to your computer and use it in GitHub Desktop.
List command for google calendar events.
gEvent
.command('list [date...]')
.description('List google event')
.action(async function(args, callback) {
const calendar = google.calendar({
version: 'v3',
auth: oauth2Client
});
const res = await calendar.events.list({
calendarId: 'primary',
maxResults: 10
});
const data = res.data;
const Email = gEvent.chalk.black.bgMagenta;
const Summary = gEvent.chalk.bold.red;
const Time = gEvent.chalk.bold.black.bgRed;
const Location = gEvent.chalk.green;
this.log(Email('Email: '), data.summary);
this.log();
data.items.forEach(({ summary, start, end, location, htmlLink }) => {
this.log(Summary(summary));
this.log();
const startTime = moment(start.dateTime).format('MMMM Do YYYY, h:mm:ss a');
const endTime = moment(end.dateTime).format('MMMM Do YYYY, h:mm:ss a');
this.log(Time('Start Time: '), startTime, ' ', Time('Start Time: '), endTime);
this.log(Location(location));
this.log(htmlLink);
this.log();
this.log();
});
callback();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment