Exemplo n.º 1
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)
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 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)))}