Ejemplo 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)
Ejemplo 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)
Ejemplo n.º 3
0
    def get_events(self):
        """Populate the event list with Google Calendar events."""

        calendars = LocationCalendar.objects.all_for_location(self.location)
        if not calendars:
            return None

        client = CalendarClient()
        for calendar in calendars:
            feed_uri = client.GetCalendarEventFeedUri(
                calendar=calendar.calendar_id,
                projection=self._GCAL_PROJECTION,
                visibility=self._GCAL_VISIBILITY)
            feed_args = {'uri': feed_uri}
            feed_args.update(self.provide_feed_args())

            #  If no start or end date have been given by a child event list, restrict
            #  the query to the dates by which we're filtering sessions, being sure to
            #  add one day to the end, given that the Google Calendar API treats the end
            #  date as exclusive
            has_dates = False
            if 'query' in feed_args:
                query = feed_args['query']
                has_dates = bool(query.start_min) or bool(query.start_max)

            if not has_dates:

                start_dt = end_dt = None
                if self.filters.start_date:
                    start_dt = self.rfc3339_localized(self.filters.start_date)
                if self.filters.end_date:
                    end_dt = self.rfc3339_localized(self.filters.end_date +
                                                    datetime.timedelta(days=1))

                if 'query' in feed_args:
                    new_query = feed_args['query']
                    new_query.start_min = start_dt
                    new_query.start_max = end_dt
                else:
                    new_query = CalendarEventQuery(start_min=start_dt,
                                                   start_max=end_dt)
                feed_args['query'] = new_query

            #  Allow a child event list to determine how to handle an event
            feed = client.GetCalendarEventFeed(**feed_args)
            self._events[calendar] = []
            for event in feed.entry:
                self.handle_event(calendar, event)
Ejemplo n.º 4
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
Ejemplo n.º 5
0
	def provide_feed_args(self):
		"""Return a query that restricts the events to a single day."""
		return {'query': CalendarEventQuery(
										start_min=self.rfc3339_localized(self.day),
										start_max=self.rfc3339_localized(self.day + datetime.timedelta(days=1)))}