Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current and next meeting #259

Closed
wdbprog opened this issue Sep 22, 2017 · 3 comments
Closed

current and next meeting #259

wdbprog opened this issue Sep 22, 2017 · 3 comments

Comments

@wdbprog
Copy link

wdbprog commented Sep 22, 2017

Hi,

Ive been this kind of code for a while now, to retrieve the current and next meetings of a bunch of meeting rooms in a roomlist:

#current meeting
current = FilteredItems.filter(
	start__lt=tz.localize(EWSDateTime(year, month, day,hour,minute,second)),
	end__gt=tz.localize(EWSDateTime(year, month, day,hour,minute,second)),
)
if current:
#processing

#next meeting
if not current:
	#No current meeting, just find the next one today
	 next = FilteredItems.filter(start__range=(
		tz.localize(EWSDateTime(year, month, day,hour,minute,second)),
		tz.localize(EWSDateTime(year, month, day, 23))
	  ))
else:
	#if there is a current meeting, find next one
	next = FilteredItems.filter(start__range=(
		current.end,
		tz.localize(EWSDateTime(year, month, day, 23))
	))

But now I noticed that the recurring meetings where not being displayed in this way. And I read that the calendar.view method does show these.
Now I wanna change to the calendar.view method of getting the meetings, but since the filter option does not work on this, I can't find a way how to filter this to a current and next meeting

testitems = room_account.calendar.view(
	start=tz.localize(EWSDateTime(year, month, day,1)),
	end=tz.localize(EWSDateTime(year, month, day,23)),
)

Is there an easy way to filter with the calandar.view? I tried things like adding the filter in the start & end parameters but this doesn't seem to have the same effect as the filter() function.

@ecederstrand
Copy link
Owner

EWS does not allow restrictions in combination with a calendar view, and the calendar view only accepts a start and end datetime. So you need to do the filtering client-side:

def matches_some_condition(item):
    # Return True here if the item matches your requirements
   return len(item.subject) > 17

matching_items = filter(matches_some_condition, account.calendar.view(...))

@ecederstrand
Copy link
Owner

Also, the CalendarItem element in EWS has an AdjacentMeetings field that we don't support yet (see #203). It could be helpful in your case.

@ecederstrand
Copy link
Owner

To get the current and next meeting, I would probably just fetch a healthy chunk of the calendar and check the first two items:

current_meeting, next_meeting = None, None
now = UTC_NOW()
for item in account.calendar.view(start=now, end=now + timedelta(days=7), max_items=2):
    if item.start <= now and item.end >= now:
        current_meeting = item
    else:
        next_meeting = item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants