如何在 Perl 中将多个日历(iCal 格式)合并为一个?
我有几个不重叠的 ical 文件,我想将它们合并到一个 ical 文件中。
执行此操作的首选方法是什么?
I have several non-overlapping ical files that I want to merge into one ical file.
What is the preferred way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
阅读 @knarf 的正确(自我)答案并格式化 iCalendar 文件后在 support.google.com,我成功地使用了这个:
这需要整个第一个参数文件,但不是最后一行(页脚),并连接第二个参数文件而不带标题。
当最常见的日历代理加载时,事件重复将自动删除。
After reading correct (self)-answer from @knarf and Format iCalendar files at support.google.com, I succesfully used this:
This take whole first argument file but not last line (footer) and concatenate second argument file without header.
Event duplication will be automatically dropped when loaded by most common Calendar Agent.
我最终连接了每个没有页眉/页脚的文件,并手动添加了页眉/页脚。
(我不能接受我自己两天内的答案)
I ended up concatenate every file without their header/footer and adding header/footer manually.
(I can't accept my own answer whithin 2 days)
有几个选项(恕我直言,对您的任务从最有用到最有用排序):
如果您更喜欢使用“标准”DateTime 模块集进行日期时间操作,您可以使用
DateTime::Format::ICal
。但是,该模块解析 iCal 格式的数据,但不解析文件。为了解析/组合多个文件,您可以使用
iCal::解析器
。从概要(参见从底部开始的第 3 行):或者
但是,该模块不会将生成的合并数据打印回文件中,至少据我所知。
Data::ICal
模块集有解析和打印,主模块 Data::ICal 能够生成文件。我无法找到如何正式合并不同日历的方法,但通过循环第二个日历对象的
条目
和属性
应该相当简单(一个是 arrayref,一个是哈希)并使用要合并的第一个日历对象的add_entry()
和add_property()
。我认为您还应该能够将
ical::Parser
合并数据转换为Data::ICal
,因为前者会生成Text:: 列表vFile::asData
对象(日期由DateTime
对象替换);后者有parse_object()
方法来解析Text::vFile::asData
对象。There are a couple of options (ordered IMHO least useful to most useful for your task):
If you prefer to use the "standard" DateTime set of modules for datetime manipulation, you can parse in and print calendars using
DateTime::Format::ICal
. However, that module parses iCal formatted data but not files.For purpose of parsing/combining multiple files, you can use
iCal::Parser
. From SYNOPSIS (see line #3 from the botom):Or
However, this module doesn't print the resulting merged data back into a file, at least that I know of.
Data::ICal
set of modules has both parsing and printing, with main module Data::ICal capable of generating a file.I wasn't able to find out how to merge the different calendars officially, but it should be fairly trivially to do by looping over second calendar object's
entries
andproperties
(one's an arrayref one is a hash) and usingadd_entry()
andadd_property()
of the first calendar object to merge.I think you should also be able to convert
ical::Parser
merged data intoData::ICal
, since the former produces lists ofText::vFile::asData
objects (with dates replaced byDateTime
objects); and the latter hasparse_object()
method to parseText::vFile::asData
objects.