Beispiel #1
0
def get_busy_free_times(events, dStart, dEnd, tStart, tEnd):
    busytimes = []
    freetimes = []
    
    begin = arrow.get(dStart)
    end = arrow.get(dEnd)
    time_begin = combine_date_time(begin, arrow.get(tStart))
    time_end = combine_date_time(begin, arrow.get(tEnd))
    i = 0

    for day in arrow.Arrow.range('day',begin,end):
      busytimes_today = Agenda()
      
      for e in events[i:]:
        if same_date(day.isoformat(), e['start']):
          busytimes_today.append(Appt.from_iso_date(e['start'],e['end'],'Busy')) #using 'Busy' because we don't want private info any further
          i = i+1

      #we have all busy times for a single day now
      #lets generate free times from busy times and and append both to their respective arrays
      timeframe = Appt.from_iso_date(time_begin,time_end,"Free Time")
      freetimes.append(busytimes_today.complement(timeframe))
      busytimes.append(busytimes_today.normalized())

      #advance the day to sync with the next iteration
      time_begin = next_day(time_begin)
      time_end = next_day(time_end)


    #return this as a dict of the free and busy times
    return {"busy":busytimes, "free":freetimes}
Beispiel #2
0
def get_free_times(busytimes, dStart, dEnd, tStart, tEnd):
    freetimes = []

    begin = arrow.get(dStart)
    end = arrow.get(dEnd)
    time_begin = combine_date_time(begin, arrow.get(tStart))
    time_end = combine_date_time(begin, arrow.get(tEnd))
    i = 0

    for day in busytimes:
      busytimes_today = Agenda()

      for item in day:
        busytimes_today.append(Appt.from_iso_date(item['start'],item['end'],item['descr']))

      timeframe = Appt.from_iso_date(time_begin,time_end,"Free Time")
      freetimes.append(busytimes_today.complement(timeframe))

      #advance the day to sync with the next iteration
      time_begin = next_day(time_begin)
      time_end = next_day(time_end)

    return freetimes
Beispiel #3
0
from agenda import Appt, Agenda
import sys
import argparse

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Find a time we can all meet.")
    parser.add_argument('date', help="Date to check for available times, format like 2012.05.31")
    parser.add_argument('earliest', help="Earliest potential time to start, format like 8:30")
    parser.add_argument('latest', help="Latest potential time to end, format like 18:00")
    parser.add_argument('participant', help="A text file containing an agenda, e.g., 'charles.ag'", 
                         nargs="*", type=argparse.FileType('r'))

    available = Agenda()
    args = parser.parse_args()
    blockspec = args.date + " " + args.earliest + " " + args.latest + "|Available"
    freeblock = Appt.from_string(blockspec)
    available.append(freeblock)

    appointments = Agenda()   # Create empty agenda

    for f in args.participant:  
        participant = Agenda.from_file(f)
        for appt in participant:   # Cycle through every appointment 
            appointments.append(appt)   
    available = appointments.complement(freeblock)

    if len(available) == 0:
        print("No free times in common")
    else:
        print(available)
Beispiel #4
0
def get_busy_times():
    app.logger.debug("Getting busy times")

    calendars = request.form.getlist('calendar')

    begin_date = arrow.get(flask.session['begin_date']).date()
    end_date = arrow.get(flask.session['end_date']).date()
    start_time = arrow.get(interpret_time(
        flask.session['startTime'])).replace(seconds=+1)
    end_time = arrow.get(interpret_time(flask.session['endTime']))

    begin_date_and_time = combine_date_and_time(begin_date, start_time)
    end_date_and_time = combine_date_and_time(end_date, end_time)

    gcal_service = get_gcal_service(valid_credentials())
    result = Agenda()
    flask.g.free_times = []
    for calID in calendars:  #Gets all calendars
        events = gcal_service.events().list(calendarId=calID,
                                            timeMin=begin_date_and_time,
                                            timeMax=end_date_and_time,
                                            singleEvents=True,
                                            orderBy='startTime').execute()
        modified_events = restrict_events_not_in_range(events, start_time,
                                                       end_time)

        for i in range(len(modified_events)):  #Gets all events
            # title = modified_events[i]['summary']
            start = modified_events[i]['start']['dateTime']
            end = modified_events[i]['end']['dateTime']
            datetime_start = parser.parse(start)
            datetime_end = parser.parse(end)
            appointment = Appt(datetime_start.date(), datetime_start.time(),
                               datetime_end.time())
            result.append(appointment)

    day_span = [
        day.datetime
        for day in arrow.Arrow.range('day', parser.parse(begin_date_and_time),
                                     (parser.parse(end_date_and_time)))
    ]
    all_times = []
    for day in day_span:
        time_range = Appt(day.date(),
                          parser.parse(begin_date_and_time).time(),
                          parser.parse(end_date_and_time).time())

        complement = result.complement(time_range)
        complement = str(complement)

        if ("\n" in str(complement)):
            tmp = complement.split("\n")
            for time in tmp:
                flask.g.free_times.append(time)
        else:
            flask.g.free_times.append(complement)

    flask.g.free_times = sorted(flask.g.free_times)

    flask.session['free_times'] = flask.g.free_times

    clear_db(
    )  # removes all other unique id's from this database, but not the creators
    if collection.find({"user_id": flask.session["user_id"]}):
        remove_from_mongo(flask.session["user_id"])
    store_in_mongo(flask.g.free_times, flask.session["user_id"], True)

    if flask.session["user_id"] == 'creator':
        return render_template('index.html')
    else:
        return render_template('invitee.html')