From 832522ab8700d26a23fb24b1b59cfb968e46b35a Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 13 Nov 2015 21:53:21 +0000 Subject: fetch all events in all calendars --- fetch-calendar | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 fetch-calendar diff --git a/fetch-calendar b/fetch-calendar new file mode 100644 index 0000000..7789fc6 --- /dev/null +++ b/fetch-calendar @@ -0,0 +1,50 @@ +#!/usr/bin/env perl +use warnings; +use 5.020; +use open ':std',':locale'; +use Net::Google::DataAPI::Auth::OAuth2; +use Net::OAuth2::AccessToken; +use Config::General; +use Net::Google::CalendarV3; +use POSIX 'strftime'; +use Data::Printer; + +sub Net::Google::CalendarV3::get_all_calendars { + my ($self) = @_; + my $res = $self->_service->get('/users/me/calendarList', { } ); + die $res->error unless $res->success; + $self->calendars($res->res->{items}); +} + +my $config_file = Config::General->new('google-to-text.conf'); +my %config = $config_file->getall; +my $oauth2 = Net::Google::DataAPI::Auth::OAuth2->new( + client_id => $config{oauth2}->{client_id}, + client_secret => $config{oauth2}->{client_secret}, + scope => ['https://www.googleapis.com/auth/calendar.readonly'], +); +my $token = Net::OAuth2::AccessToken->session_thaw( + $config{oauth2}->{token}, + profile => $oauth2->oauth2_webserver, +); +my $gcal = Net::Google::CalendarV3->new({ + oauth2_access_token => $token->access_token, +}); + +$gcal->get_all_calendars(); +for my $calendar (@{$gcal->calendars}) { + say sprintf 'Calendar %s (%s / %s)', + $calendar->id,$calendar->summary,$calendar->description//''; + $gcal->set_calendar($calendar); + for my $event ($gcal->get_events( + timeMin => strftime('%FT%TZ',gmtime), + timeMax => strftime('%FT%TZ',gmtime(time+86400*7)), + orderBy => 'startTime', + singleEvents => 'True', + )) { + say sprintf " > %s %s - %s\n >> %s\n", + $event->summary, + ($event->start->get)[0],($event->end->get)[0], + $event->description//''; + } +} -- cgit v1.2.3