Skip to content

Instantly share code, notes, and snippets.

@Tolsee
Created August 9, 2018 04:44
Show Gist options
  • Save Tolsee/07a9b378756707ed8cb85e986a6a755d to your computer and use it in GitHub Desktop.
Save Tolsee/07a9b378756707ed8cb85e986a6a755d to your computer and use it in GitHub Desktop.
gEvent
.command('list')
.option('-f, --from [date]', 'Get events from the date[chrono based date parsing]')
.option('-t, --to [date]', 'Get events until the date [chrono based date parsing]')
.option('-r, --results <events>', 'Number of events to show')
.description('List google event')
.action(async function(args, callback) {
const calender = google.calendar({
version: 'v3',
auth: oauth2Client
});
let options = {
calendarId: 'primary',
singleEvents: true,
maxResults: 10
};
if(args.options.from) {
const time = chrono.parseDate(args.options.from);
if (time) {
options.timeMin = time.toISOString();
} else {
this.log(Yellow('Warning: cannot parse from date'));
}
}
if(args.options.to) {
const time = chrono.parseDate(args.options.to);
if (time) {
options.timeMax = time.toISOString();
} else {
this.log(Yellow('Warning: cannot parse to date'));
}
}
if(args.options.results) options.maxResults = args.options.results;
const res = await calender.events.list(options);
const data = res.data;
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 || 'Location is not available.'));
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