【问题标题】:How do I disable notifications/reminder and set events to free time with Perl's ICal::Entry?如何使用 Perl 的 ICal::Entry 禁用通知/提醒并将事件设置为空闲时间?
【发布时间】:2013-10-02 17:48:10
【问题描述】:

不幸的是,我的大学懒得为我们的公共活动制作谷歌日历或.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;

谢谢!

【问题讨论】:

    标签: perl google-calendar-api icalendar


    【解决方案1】:

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

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

    所以现在,要回答您的问题,请导入这 2 个模块...

    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);
    

    【讨论】:

    • 谢谢!但是,这不是设置警报并将我标记为忙碌而不是禁用谷歌将施加的默认警报吗?忙碌的时候也一样,而不是想要免费?
    • 是的,你是对的,我的错!那么谁设置了默认闹钟呢? print $calendar-&gt;as_string;的结果是OK的,那里没有默认报警。如果是谷歌日历,那么你是否检查了它的设置是否有默认值。如果从应用程序端无事可做,那么也许您必须创建如上所示的警报,但日期为过去,并查看如何将其导入 GC。
    • 是的,如果没有指定,谷歌会创建默认警报。我虽然在 ICal 标准或其他东西中有一个明确的“无提醒”属性。
    • 我快速检查了 iCalendar 文件格式RFC5545 并没有发现任何“无提醒”属性。所以这似乎纯粹是谷歌日历网络应用程序的错。尝试在导入之前按照here 的说明更改 GC 的设置,如果可行,请告诉我们。
    • 好的,谢谢,我希望有一些明确的不提醒。猜猜我每次添加.ics 时都必须更改gCalendars 设置。我在 Google 或 iCal 中都没有找到“默认将事件标记为空闲时间”选项。真气。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-08
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 2016-06-05
    • 1970-01-01
    相关资源
    最近更新 更多