如何从活动链接中获取活动信息?

时间:2016-10-21 00:56:52

标签: python-2.7 caldav

我想使用CalDAV python模块从事件中获取整个信息,我设法获得该事件的链接,但我不明白如何从该事件中获取事件详细信息,所以我有链接参加活动:

https://mail.example.com:443/public-calendars/example.com/9A0F7585-A952-4E0C-868C-0C072A2D8740/9a0f7585-a952-4e0c-868c-0c072a2d8740-0000048a.eml

我正在尝试这个以获取活动详情:

event = 'https://mail.example.com:443/public-calendars/example.com/9A0F7585-A952-4E0C-868C-0C072A2D8740/9a0f7585-a952-4e0c-868c-0c072a2d8740-0000048a.eml'
eventDetail = caldav.Event(event).load()

但我收到错误:

AttributeError: 'str' object has no attribute 'request'

我想得到的是这样的:

BEGIN:VEVENT
SUMMARY:event-title
DTSTART;TZID=Europe/Warsaw:20150305T130000
DTEND;TZID=Europe/Warsaw:20150305T140000
DTSTAMP:20150624T170317Z
UID:9149F870-5475-4120-9EE5-1A06E857807B
SEQUENCE:1
EXDATE;TZID=Europe/Warsaw:20150618T130000
EXDATE;TZID=Europe/Warsaw:20150305T130000
EXDATE;TZID=Europe/Warsaw:20150430T130000
CREATED:20150226T105018Z
DESCRIPTION:
LAST-MODIFIED:20150616T094907Z
LOCATION:
RRULE:FREQ=WEEKLY;UNTIL=20150624T235959Z;INTERVAL=1
STATUS:CONFIRMED
TRANSP:OPAQUE
BEGIN:VALARM
ACTION:NONE
TRIGGER;VALUE=DATE-TIME:19760401T005545Z
UID:FC67F59E-5540-47BE-ACFA-FE229771EC11
X-WR-ALARMUID:FC67F59E-5540-47BE-ACFA-FE229771EC11
END:VALARM
END:VEVENT

我想把它放到一个变量中,以便我可以查看该信息并搜索我需要的内容或将其发送到文件中。

2 个答案:

答案 0 :(得分:0)

查看模块caldav/objects.py 我明白了:

def __init__(self, client=None, url=None, data=None, parent=None, id=None)

您正在传递URL作为客户端对象(第一个参数),因此错误。

也许这会起作用,但可能不会(加载,很可能需要客户端对象):

eventDetail = caldav.Event(url=event).load()

但是进一步查看模块,我在日历对象上看到event_by_url

class Calendar(DAVObject):
  ...
  def event_by_url(self, href, data=None):

据推测,您已经可以访问日历对象,所以我想这可能很简单:

event = calendar.event_by_url("/calendars/123.ics")

答案 1 :(得分:0)

获取事件网址并尝试以下操作:

event_url = 'https://mail.example.com:443/public-calendars/example.com/9A0F7585-A952-4E0C-868C-0C072A2D8740/9a0f7585-a952-4e0c-868c-0c072a2d8740-0000048a.eml'
eventl = calendar.event_by_url(event_url)

然后您可以像这样将数据加载到对象“”中:

event_data = eventl.vobject_instance.vevent

并且,例如,像这样访问“SUMMARY”:

event_summary = eventl.vobject_instance.vevent.summary.value