我希望此I解决方案、此功能可以通过电子邮件或与会者的日历ID获取与会者、与会者电子邮件的结果列表事件
def get_events_by_attendee(service, calendarId, attendee_email):
now = datetime.utcnow().isoformat() + 'Z' # 'Z' indicates UTC time
timeMin = datetime.utcnow() - timedelta(days=3) #you can change
timeMax = datetime.utcnow()+ timedelta(days=3)#you can change
print(timeMin, now)
timeMin = timeMin.isoformat() + 'Z'
timeMax = timeMax.isoformat() + 'Z'
print(timeMin)
events_result = service.events().list(calendarId=calendarId,
timeMin=timeMin,
timeMax = timeMax,
singleEvents=True,
orderBy='startTime').execute()
events = events_result.get('items', [])
if not events:
print('No upcoming events found.')
list_events = []
for event1 in events:
element_list = []
eventId = event1['id']
event = service.events().get(calendarId=calendarId, eventId=eventId).execute() #check this event have attendee or not
try:
if event['attendees']:
for attendee in event['attendees']:
if (attendee['email']==attendee_email)and(attendee['responseStatus']=='accepted'): #responseStatus 'accept' mean attendee accept your invitation
print(event['attendees'])
element_list.append(eventId)
htmlLink = event['htmlLink']
element_list.append(htmlLink)
summary = event['summary']
element_list.append(summary)
try: #this code belong to my sytems, you can pass it
description = event['description']
description = description.replace('\n', '<br>')
description = description.split('####', 1)
if description == []:
description = event['description']
except Exception as e:
description = 'Không có mô tả####'
description = description.split('####', 1)
element_list.append(description)
created = event['created']
created = dateutil.parser.parse(created) + timedelta(hours=7) #change the timezone
created = datetime(created.year, created.month, created.day, created.hour, created.minute)
element_list.append(created)
updated = event['updated']
updated = dateutil.parser.parse(updated) + timedelta(hours=7)#change the timezone
updated = datetime(updated.year, updated.month, updated.day, updated.hour, updated.minute)
element_list.append(updated)
start = event['start'].get('dateTime', event['start'].get('date'))
start = dateutil.parser.parse(start) + timedelta(hours=7)#change the timezone
start = datetime(start.year, start.month, start.day, start.hour, start.minute)
element_list.append(start)
end = event['end'].get('dateTime', event['end'].get('date'))
end = dateutil.parser.parse(end) + timedelta(hours=7)
end = datetime(end.year, end.month, end.day, end.hour, end.minute)
element_list.append(end)
status = event['status']
element_list.append(status)
attendees = event['attendees']
element_list.append(attendees)
list_events.append(element_list)
else:
pass
except Exception as e:
pass
return list_events