Skip to content

Instantly share code, notes, and snippets.

@lopnor
Created May 16, 2012 08:25
Show Gist options
  • Save lopnor/2708684 to your computer and use it in GitHub Desktop.
Save lopnor/2708684 to your computer and use it in GitHub Desktop.
#!perl
use strict;
use warnings;
use Net::Google::Calendar;
use Config::Pit;
use DateTime;
use Email::MIME;
use Data::Dumper;
use HTTP::Date ();
use FindBin;
my $mail = Email::MIME->new(do {local $/; <>});
my $body = substr($mail->body, -1024);
my $title = $mail->header('Subject');
my $start = DateTime->from_epoch(
epoch => HTTP::Date::str2time($mail->header('Date')),
time_zone => 'local',
);
my ($received) = $mail->header('Received');
my $end = DateTime->from_epoch(
epoch => HTTP::Date::str2time([split(';', $received)]->[-1]),
time_zone => 'local',
);
my $config = do "$FindBin::Bin/config.pl" or die;
my $calendar_title = 'cron logs';
if ($body !~ m{All tasks finished successfully!!! :\)}) {
$calendar_title .= ' fail'
};
my $client = Net::Google::Calendar->new;
$client->login(@$config{qw(username password)});
my @cals = $client->get_calendars;
if (my ($cal) = grep {$_->title eq $calendar_title} @cals) {
$client->set_calendar($cal);
} else {
die "calendar $calendar_title not found";
}
my $entry = Net::Google::Calendar::Entry->new;
$entry->title($title);
$entry->when($start, $end);
$entry->content($body);
$client->add_entry($entry);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment