1

不幸的是,我的大学懒得制作谷歌日历或.ics我们的公共活动。相反,他们选择给我们写一封电子邮件,其中包含一个包含日期列表的格式化文本文件。我有一个 Perl 脚本将所述列表转换为 iCalendar ( .ics) 文件。我想.ics稍后将其导入我的谷歌日历。

到目前为止,脚本运行良好,但现在我想禁用标准通知(电子邮件和弹出窗口)并将事件设置为空闲时间(而不是默认忙碌)。问题是,我没有从Data::ICal::Entry::FreeBusyData::ICal::Entry::Alarm::Display的文档中得到任何有用的信息。请善待我,为我提供正确的属性以添加到$event->add_properties(...)下面脚本中的行:

#!/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;

非常感谢你!

4

1 回答 1

1

首先是一些一般性的评论:

  1. 添加use strict;
  2. 添加my循环foreach my $eventstring (@events) {并将其从下面的行中删除my $eventstring =~ s/(\d+\.\d+\.\d+)//;
  3. 作为一个好习惯,尽量避免使用裸词FILE并将文件句柄定义为标量变量open my $FILE,$ARGV[0]

所以现在,要回答你的问题,导入这两个模块......

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

...而且我相信您必须在代码中添加以下内容:

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);
于 2013-10-02T09:48:10.307 回答