Exemplo n.º 1
0
def timerange():
	app.logger.debug("entering timerange")
	flask.session['start_time'] = interpret_time(request.form.get('start_time'))
	flask.session['end_time'] = interpret_time(request.form.get('end_time'))

	gcal_service = get_gcal_service(valid_credentials())
	page_token = None
	
	
	agenda = Agenda() #busy time agenda
	for cal in flask.session['cals']:
		events = gcal_service.events().list(
		calendarId = cal,
		singleEvents = True,
		maxResults = 100,
		timeMin = (flask.session['begin_date']).format('YYYY-MM-DD HH:mm:ss ZZ'),
		timeMax = (next_day(flask.session['end_date'])).format('YYYY-MM-DD HH:mm:ss ZZ'),
		pageToken = page_token,).execute()
		
		#adds events in 'Appt' format to an "agenda" 
		for event in events['items']:
			if 'transparency' in event:
				continue
			#appointment
			ev_start = arrow.get(event['start']['dateTime'])
			ev_end = arrow.get(event['end']['dateTime'])
			new_apt = Appt(ev_start, ev_end,event['summary'])
			agenda.append(new_apt)
		
	#created an agenda containing all of the google calendar events that fall into the 
	#date range 
	
	#Complement busy_time agenda with a huge 'freetime' appt that spans the whole date 
	#range
	comp_agenda = agenda.complement(date_range_appt())
	final_agenda = comp_agenda.intersect(free_block_agenda())
	result = final_agenda.to_dict()
	
	for a in result:
		collection.insert({"type": "appt", "begin": a['begin'], "end": a['end'],"desc": a['desc']})
	
	flask.session['appointments'] = get_appts()
	return flask.render_template("display.html")
Exemplo n.º 2
0
def intersect_cals():
	gcal_service = get_gcal_service(valid_credentials())
	page_token = None
	
	
	agenda = Agenda() #busy time agenda
	for cal in flask.session['cals']:
		events = gcal_service.events().list(
		calendarId = cal,
		singleEvents = True,
		maxResults = 100,
		timeMin = (flask.session['begin_date']).format('YYYY-MM-DD HH:mm:ss ZZ'),
		timeMax = (next_day(flask.session['end_date'])).format('YYYY-MM-DD HH:mm:ss ZZ'),
		pageToken = page_token,).execute()
		
		#adds events in 'Appt' format to an "agenda" 
		for event in events['items']:
			if 'transparency' in event:
				continue
			#appointment
			ev_start = arrow.get(event['start']['dateTime'])
			ev_end = arrow.get(event['end']['dateTime'])
			new_apt = Appt(ev_start, ev_end,event['summary'])
			agenda.append(new_apt)
	
	comp_agenda = Agenda()		
	for appt in flask.session['appointments']:
		comp_appt = Appt(appt["begin"],appt["end"],appt["desc"])
		comp_agenda.append(comp_appt)
	
	inverse_agenda = agenda.complement(date_range_appt())
	final = inverse_agenda.intersect(comp_agenda)
	result = final.to_dict()
	
	collection.remove({})
	
	for a in result:
		collection.insert({"type": "appt", "begin": a['begin'], "end": a['end'],"desc": a['desc']})

	flask.session['appointments'] = get_appts()
	return flask.render_template("display.html")