我正在努力从google中提取日历事件的出席者,发现当一个事件没有出席者时,for循环失败了。
for calendar_id in me:
count = 0
#print('\n%s' % calendar_id)
eventsResult = service.events().list(
calendarId=calendar_id,
timeMax=now,
timeMin=end_date).execute()
#orderBy='startTime').execute()
#events = eventsResult.get('items', [])
#events = eventsResult.get('items', [])
events = service.events().list(calendarId=calendar_id).execute()
events = events.get('items', [])
for event in events:
start = event['start'].get('dateTime')
print('\n' + event['summary'] + " " + "(Calendar - " + calendar_id + ")")
for attendees in event['attendees']:
attid = event.get('attendees')
atte = attendees.get('email')
try:
attid = event.get('attendees')
except Exception as e:
print("No attendees", e)
try:
atte = attendees.get('email')
except Exception as e:
print("No email found", e)
这将帮助你的for循环继续
for attendees in event['attendees']:
try:
attid = event.get(attendees)
except Exception as e:
print("No attendees", e)
try:
atte = attendees.get('email')
except Exception as e:
print("No email found", e)