在Python中搜索iCal格式文件中的事件

2024-04-26 08:00:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我只想在iCal文件中查看适用于今天的事件。这是我的代码:

from icalendar import Calendar, Event
from datetime import datetime

g = open('reachcalendar.ics','rb')
cal = Calendar.from_ical(g.read())

for component in cal.walk():
  if component.name == "VEVENT":
    if component.get('dtstart').date() == datetime.today().date()
      print component.get('summary')
      print component.get('dtstart').dt

g.close()

但这会导致无效语法:

^{pr2}$

我做错什么了?在


Tags: 文件代码fromimportgetdatetimedateif