Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!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