开发者

py-appscript filter with datetime

I am trying to use the day field of a datetime property as a filter when selecting events from an iCal calendar.

The following doesn't seem to work (to select all events for the current date):

cal = app("iCal").calendars["myCalender"].get()
cDate = datetime.now()
cEvents = cal.events[its.start_date.day==cDate.day].get()

I get the result: AttributeError: Unknown property, element or command: 'day'

However, this works (for printing the days of any events)...

cal = app("iCal").calendars["myCalender"].get()
for cEvent in cal.events.get():
    print 开发者_如何转开发cEvent.start_date.get().day


This line

cal.events[its.start_date.day==cDate.day].get()

checks its.start_date.day==cDate.day and returns False or True. As an index, this translates into 0 and 1 and takes one of the first two elements in the cal.events list. Is this what you want?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜