0

这是一个代码问题。下面是我用来从特定日期范围内的谷歌日历中检索所有日历事件的代码。我能够解析事件的一部分,但不能解析事件的一部分。

def retrieve_date_range_query(self,start_date='2013-09-28', end_date='2013-10-01'):
        print 'Date range query for events on Primary Calendar: %s to %s' % (start_date, end_date,)
        query = gdata.calendar.service.CalendarEventQuery('default', 'private', 'full')
        query.start_min = start_date
        query.start_max = end_date
        feed = self.cal_srv.CalendarQuery(query)
        print feed
        for i, an_event in enumerate(feed.entry):
            print '\t%s. %s' % (i, an_event.title.text,)
# 
            for p, a_participant in enumerate(an_event.who):
                    print '\t\t%s. %s' % (p, a_participant.email,)
# Method 1 to retrieve starttime and endtime of the event - but it fails
            for p, a_participant in enumerate(an_event.when):
                    print '\t\t%s. %s' % (p, a_participant.startTime,)
                    print '\t\t%s. %s' % (p, a_participant.endTime,)
# Method 2 to retrieve starttime and endtime of the event - this too fails
#  Value for a_when here is When: <?xml version='1.0' encoding='UTF-8'?> <ns0:when xmlns:ns0="http://schemas.google.com/g/2005" endTime="2013-09-30T09:00:00.000+05:30" startTime="2013-09-30T08:00:00.000+05:30" />
            for a_when in an_event.when:
                print '\t\tStart time: %s' % (a_when.startTime,)
                print '\t\tEnd time:   %s' % (a_when.endTime,) 

我主要从这个链接反映了上面的社区代码。并彻底分析了when和who对象的xml数据。我惊讶地发现我能够解析谁反对而不是什么时候反对。我是否缺少代码中的任何内容。是否有任何其他信息我可以提供以使其更好地理解。谢谢你的时间。

4

1 回答 1

0

我解决了问题。

变量必须像这样使用

for a_when in an_event.when:
   print '\t\tStart time: %s' % (a_when.start_time,)
   print '\t\tEnd time:   %s' % (a_when.end_time,)

我不太清楚为什么我们使用 start_time。但这就是它必须使用的方式。谢谢

于 2013-10-11T11:48:06.930 回答