I'm attempting to call the Google Calendar API and return results only containing a specific piece of text.
Using the following snippet:
eventsResult = service.events().list(
calendarId='primary', timeMin=start_time, timeMax=end_time, singleEvents=True,
orderBy='startTime').execute()
events = eventsResult.get('items', [])
if not events:
print('No upcoming events found.')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
print(start, event['summary'])
I receive results in the following format:
(u'2018-02-16', u'Foo')
(u'2018-02-16T10:00:00-07:00', u'Bar')
I am attempting to add logic to limit results to those lines containing 'Foo'
if not events:
print('No upcoming events found.')
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
if "Foo" in event:
print(start, event['summary'])
Returns nothing.
Do I need to place the if "Foo" in event: logic elsewhere? Am I misunderstanding the usage?
Aucun commentaire:
Enregistrer un commentaire