예제 #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}
예제 #2
0
def events():
    """
    retrieve the event data which was selected in the calendars 
    using AJAX
    """
    service = get_gcal_service(valid_credentials())
    selected_cals = request.json['ids']
    #print(selected_cals)
    #ret =[]
    begin_date = arrow.get(flask.session['begin_date'])
    end_date = arrow.get(flask.session['end_date'])

    if begin_date == end_date: 
        differ = 1
    else:
      differ = ((end_date - begin_date).days) + 1

    begin_query = time_el(begin_date, flask.session['begin_time'])
    end_query = time_el(end_date, flask.session['end_time'])

    #interpret free times using agenda.py
    result =[]
    busy = []
    free = Appt(arrow.get(begin_query), arrow.get(end_query))

    for day in range(differ):
        for cal_id in selected_cals:
          av_agenda = Agenda()

          events = service.events().list(calendarId=cal_id, timeMin=begin_query, timeMax=end_query, singleEvents=True, orderBy="startTime").execute() 

            for event in events['items']:
              strt = arrow.get(event['start']['dateTime'])
              end = arrow.get(event['end']['dateTime'])
              av_agenda.append(Appt(strt, end))
              result.append({'summary': event['summary'],
                          "startTime": arrow.get(event['start']['dateTime']).format("MM/DD/YYYY HH:mm"), 
                          "endTime": arrow.get(event['end']['dateTime']).format("MM/DD/YYYY HH:mm")})
            busy.append(av_agenda)
        begin_query = next_day(begin_query) # should go one day after
        end_query = next_day(end_query)
예제 #3
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
예제 #4
0
def mergeBusyTimes(newTimes, oldTimes, dStart, dEnd):
    busytimes = []
    begin = arrow.get(dStart)
    end = arrow.get(dEnd)
    i = 0
    j = 0

    for day in arrow.Arrow.range('day',begin,end):
      busytimes_today = Agenda()

      for appt in newTimes[i:]:
        if same_date(day.isoformat(), appt['start']):
          busytimes_today.append(Appt.from_iso_date(appt['start'],appt['end'],'Busy'))
          i=i+1

      if(len(oldTimes) > j):
        for appt in oldTimes[j]:
          busytimes_today.append(Appt.from_iso_date(appt['start'],appt['end'],appt['descr']))

      busytimes.append(busytimes_today)
      j=j+1

    return busytimes
예제 #5
0
    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)

    for f in args.participant:
        participant = Agenda.from_file(f)
        participant = participant.complement(freeblock)
        available = available.intersect(participant)

    if len(available) == 0:
        print("No free times in common")
    else:
        print(available)
예제 #6
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)
예제 #7
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)

    for f in args.participant: 
        participant = Agenda.from_file(f)
        available = available.intersect(participant)

    if len(available) == 0:
        print("No free times in common")

    else:
        print(available)
    

    
예제 #8
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')