Exemplo n.º 1
0
def get_events():
    client = CalendarClient(source="adicu-pericles-v1")
    client.ClientLogin(settings.GCAL_USERNAME, settings.GCAL_PASSWORD, client.source)

    uri = "https://www.google.com/calendar/feeds/" + settings.GCAL_ID + "/private/full"

    start_date = datetime.today()
    end_date = start_date + timedelta(weeks=1)

    query = CalendarEventQuery()
    query.start_min = start_date.strftime("%Y-%m-%d")
    query.start_max = end_date.strftime("%Y-%m-%d")

    return client.GetCalendarEventFeed(uri=uri, q=query)
Exemplo n.º 2
0
def get_events():
    client = CalendarClient(source='adicu-pericles-v1')
    client.ClientLogin(settings.GCAL_USERNAME, settings.GCAL_PASSWORD,
                       client.source)

    uri = "https://www.google.com/calendar/feeds/" + settings.GCAL_ID + \
                "/private/full"

    start_date = datetime.today()
    end_date = start_date + timedelta(weeks=1)

    query = CalendarEventQuery()
    query.start_min = start_date.strftime('%Y-%m-%d')
    query.start_max = end_date.strftime('%Y-%m-%d')

    return client.GetCalendarEventFeed(uri=uri, q=query)
Exemplo n.º 3
0
def _get_calendars_events(users, request):

    """
    It retrieves all avalable calendars from the current user, this means also 'Festivita italiane' and 'Compleanni ed eventi'.
    The porpouse is to get all the events from each calendar with by keyword (in this example is '*****@*****.**').
    and from each event get the date range value.

    return would be something like this:
    [
     ['*****@*****.**',
        [[datetime.datetime(2011, 8, 24, 0, 0), datetime.datetime(2011, 8, 24, 23, 59)],
        [datetime.datetime(2011, 8, 23, 0, 0), datetime.datetime(2011, 8, 23, 23, 59)],
        [datetime.datetime(2011, 8, 23, 0, 0), datetime.datetime(2011, 8, 23, 23, 59)],
        [datetime.datetime(2011, 8, 22, 0, 0), datetime.datetime(2011, 8, 22, 23, 59)]]],
     ['*****@*****.**',
        [[datetime.datetime(2011, 8, 24, 0, 0), datetime.datetime(2011, 8, 24, 23, 59)]]],
     ['*****@*****.**', []],
     ['*****@*****.**', []],
     ['*****@*****.**', []]
    ]
    """
    result = []
    client = request.gclient['CalendarClient']

    # get all calendars
    query_holidays = CalendarEventQuery()
    query_holidays.start_min = request.params.get('start')
    query_holidays.start_max = request.params.get('end')

    cal_holidays_ranges = []
    try:
        italian_holidays = client.GetCalendarEventFeed(
                uri='https://www.google.com/calendar/feeds/en.italian%23holiday%40group.v.calendar.google.com/private/full',
                q=query_holidays)
        for holiday in italian_holidays.entry:
            s = parse(holiday.when[0].start)
            e = parse(holiday.when[0].end)
            cal_holidays_ranges.append([s, e-timedelta(minutes=1)])
    except RequestError: # gracefully ignore request errors
        pass

    settings = get_current_registry().settings
    attendees = settings.get('penelope.core.vacancy_email')
    query = CalendarEventQuery(text_query = attendees)
    query.start_min = request.params.get('start')
    query.start_max = request.params.get('end')

    for user in users:
        username = user.email
        feed_uri = client.GetCalendarEventFeedUri(calendar=username, visibility='private', projection='full')
        cal_events_ranges = deepcopy(cal_holidays_ranges)

        # get the event feed using the feed_uri and the query params in order to get only those with '*****@*****.**'
        try:
            events_feed = client.GetCalendarEventFeed(uri=feed_uri, q=query)
            for an_event in events_feed.entry:
                if not an_event.when:
                    continue
                s = parse(an_event.when[0].start)
                e = parse(an_event.when[0].end)
                cal_events_ranges.append([s, e-timedelta(minutes=1)])
        except RequestError: # gracefully ignore request errors
            pass
        result.append([username,cal_events_ranges])
    return result