3

I want to get events of my calendar in a particular date using python O365 library.

#code to create account instance
schedule = account.schedule()

for item in schedule.get_events(query= "start/dateTime ge '2019-11-23T08:00' and end/dateTime ge '2019-11-23T19:00'",include_recurring=False):

    print(item)

When I do this, I got all the events including the events not related to the date I specified.

I have gone through the docs and source code of O365 Calendar Query class, they are using 2 formats to get date value in query parameter.

1)Query instance - I tried but don't know how to pass value for this instance.

2)String instance - Above given code, but not getting the expected answer.

Please explain the format to pass Query instance and also point out why the above code is not extracts the exact date events?

Vanjith
  • 520
  • 4
  • 23
  • I know this has been asked a long time ago but might help others. the second condition, instead of gt, the condition should be lt (less than). start/dateTime ge '2019-11-23T08:00' and end/dateTime lt '2019-11-23T19:00'. – chip Sep 29 '20 at 19:26

1 Answers1

0

To create and use a Query instance with a start and end time and date:

import datetime

...

start = datetime.datetime.combine(datetime.date(2019, 11, 23), datetime.time(8, 00))
end = datetime.datetime.combine(datetime.date(2021, 11, 23), datetime.time(19, 00))

query = calendar.new_query('start').greater_equal(start)
query.new('end').less_equal(end)
items = calendar.get_events(query=query, include_recurring=False)

for item in items:
    print(item)

calendar.new_query creates a new query and query.new merges 2 queries together, in this case 'start' and 'end'.

nelson2tm
  • 167
  • 8
  • 16