How do I disable notifications/reminder and set events to free time with Perl's ICal::Entry?

StackOverflow https://stackoverflow.com/questions/19132976

Pregunta

Unforunately my university was too lazy to make a google calendar or .ics for our public events. Instead they choose to wirte us an email with a formatted text file containing a list of the dates. I have a Perl script to convert said list, into an iCalendar (.ics) file. I want to import that .ics into my google calendar later.

So far the script works very well but now I want to disable the standard notifications (E-Mail and PopUp) and set the events to be free time (instead of default busy). The problem is, that I don't get anything usefull out of the documentation for Data::ICal::Entry::FreeBusy and Data::ICal::Entry::Alarm::Display. Be so kind an provide me with the right properties to add to the $event->add_properties(...) line in the script below:

#!/usr/bin/perl -w
# Converts a specially formated text file (list of events) into an .ics
# (iCalendar) file for import into Google-Calendar or other calendar
# applications.

use Date::ICal;
use Data::ICal;
use Data::ICal::Entry::Event;

# Read file into one long string
open FILE, $ARGV[0] or die "Couldn't open file: $!";
my $fstring = join("", <FILE>);
close FILE;

# Prepare calendar
my $calendar = Data::ICal->new();
$calendar->add_properties( method=>"PUBLISH",);

# Add events depending on what was found in file
my @events = split("\n\n", $fstring);
foreach $eventstring (@events) {
    my $eventstring =~ s/(\d+\.\d+\.\d+)//; # remove date from the string
    my $datestring = $1;                    #+but save it for processing:
    ($day, $month, $year) = split(/\./, $datestring);
    $title = ( split /\n/, $eventstring )[1]; # what is left is the title

    my $event = Data::ICal::Entry::Event->new();
    $event->add_properties(
        summary     => "Kolloquium: $title",
        description => $eventstring,          #+and the long description
        dtstart     => Date::ICal->new( year=>"20$year", month=>$month, day=>$day, hour=>17, min=>15 )->ical,
        dtend       => Date::ICal->new( year=>"20$year", month=>$month, day=>$day, hour=>18, min=>15 )->ical,
        dtstamp     => Date::ICal->new( epoch => time )->ical,
        # MISSING HERE: Right FREEBUSY and ALARM properties. PLEASE HELP!
    );
    $calendar->add_entry($event);
}

print $calendar->as_string;

Thank you kindly!

¿Fue útil?

Solución

First of all some general remarks:

  1. add use strict;
  2. add my in the loop foreach my $eventstring (@events) { and remove it from below line my $eventstring =~ s/(\d+\.\d+\.\d+)//;
  3. as a good practice, try to avoid the bareword FILE and define the filehandle as a scalar variable open my $FILE,$ARGV[0]

So now, to answer your question, import those 2 modules...

use Data::ICal::Entry::FreeBusy;
use Data::ICal::Entry::Alarm::Display;

...and I believe you have to add the following to your code:

my $event = Data::ICal::Entry::Event->new();
$event->add_properties(
    summary     => "Kolloquium: $title",
    description => $eventstring,          #+and the long description
    dtstart     => Date::ICal->new( year=>"20$year", month=>$month, day=>$day, hour=>17, min=>15 )->ical,
    dtend       => Date::ICal->new( year=>"20$year", month=>$month, day=>$day, hour=>18, min=>15 )->ical,
    dtstamp     => Date::ICal->new( epoch => time )->ical,
);
my $vfreebusy = Data::ICal::Entry::FreeBusy->new();
$vfreebusy->add_properties(
    organizer => 'MAILTO:jsmith@host.com',
    freebusy   => Date::ICal->new( epoch => ... )->ical . '/' . Date::ICal->new( epoch => ... )->ical, #don't forget to define the time!
);
my $valarm = Data::ICal::Entry::Alarm::Display->new();
$valarm->add_properties(
    description => "Wake up!",
    trigger   => [ Date::ICal->new( epoch => ... )->ical, { value => 'DATE-TIME' } ], #don't forget to define the time!
);

$calendar->add_entry($valarm);
$calendar->add_entry($vfreebusy);
$calendar->add_entry($event);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top