使用Python中的icalendar模块提取日历扩展

发布于 2024-11-30 23:55:03 字数 902 浏览 1 评论 0原文

使用 Codespeak 的 iCalendar python 模块从 iCalendar 文件中读取和提取数据,如何提取 vText 中包含的各种私有日历扩展?

该标准允许供应商特定的扩展,所有扩展均以 X- 前缀开头。

我关心的都具有以下格式:

X-VENDOR-CUSTOMFIELD;NAME="Custom Type";ID=21;TYPE=CustomAsset:AssetFormat Template
X-VENDOR-CUSTOMFIELD;NAME="Primary Contact";ID=22;TYPE=SingleLine: A Contact Name

我想获取每次出现的 X-VENDOR-CUSTOMFIELD 的“名称”、ID 和类型值。

按扩展名查找将返回正确计数的列表:

custom_fields = event.get('X-VENDOR-CUSTOMFIELD');
print type(custom_fields) # yields list with 'vText' types

vText 将返回转义和编码的文本值:

Asset Format Template
A Contact Name

这只是我需要的一部分。我应该尝试采用不同的方式来获取每个扩展的值吗?

我查看了关于使用Python解析文件(ics/icalendar)的另一篇SO文章 供参考,但这与我的问题不完全相同。

与此相关的是,iCalendar 更好用还是我应该考虑 vobject?

Using Codespeak's iCalendar python module to read and extract data from an iCalendar file, how would you pull out the various private Calendar extensions that are enclosed within vText?

The standard allows vendor-specific extensions, all starting with the X- prefix.

The ones I care about all have the following format:

X-VENDOR-CUSTOMFIELD;NAME="Custom Type";ID=21;TYPE=CustomAsset:AssetFormat Template
X-VENDOR-CUSTOMFIELD;NAME="Primary Contact";ID=22;TYPE=SingleLine: A Contact Name

I want to get the 'Name', ID and Type values for each occurrence of X-VENDOR-CUSTOMFIELD.

Looking up by the extension name will return a list of the right count:

custom_fields = event.get('X-VENDOR-CUSTOMFIELD');
print type(custom_fields) # yields list with 'vText' types

vText will give me back the escaped and encoded text value:

Asset Format Template
A Contact Name

This is just part of what I need. Is there a different way I should try to pick up the values of each extension?

I looked at this other SO post about Parsing files (ics/ icalendar) using Python for reference but it's not quite the same question as mine.

Related to this, is iCalendar better to use or should I consider vobject?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文