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")
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")
def free_block_agenda(): """ returns an agenda of appointments of the selected start time and end time from the html form '/timerange' for every day in the date range also selected by the user """ free_block_agenda = Agenda() arrow_start = arrow.get(flask.session['begin_date']) arrow_end = arrow.get(flask.session['end_date']) arrow_start.replace(hour = 0) arrow_end.replace(hour = 0) start_time = arrow.get(flask.session['start_time']) end_time = arrow.get(flask.session['end_time']) for r in arrow.Arrow.span_range('day',arrow_start,arrow_end): rstart = r[0] rend = r[1] rstart = rstart.replace(hour= start_time.hour, minute = start_time.minute) rend = rend.replace(hour = end_time.hour, minute = end_time.minute) desc = "freeblock" free_block_agenda.append(Appt(rstart,rend,desc)) return free_block_agenda