def _adjust_time(military_time, offset_minutes): hour_and_minutes = military_time.split(':') hour = int(hour_and_minutes[0]) minutes = int(hour_and_minutes[1]) return datetime.combine( date.today(), time(hour, minutes), tzinfo=default_timezone(), ) + timedelta(minutes=offset_minutes)
def get_first_matching_datetime_of_term(meeting_days, start_date, time_hours, time_minutes): first_meeting = None meeting_day_indices = [DAYS.index(day) for day in meeting_days] for index in range(7): # Monday is 0 and Sunday is 6 day_index = (start_date.weekday() + index) % 7 if day_index in meeting_day_indices: first_day = start_date + timedelta(days=index) first_meeting = default_timezone().localize( datetime( first_day.year, first_day.month, first_day.day, time_hours, time_minutes, ), ) break return first_meeting
def _schedule_recurring_events_in_kaltura( self, category_ids, course_label, instructors, meeting, publish_type, recording_type, room, term_id, ): # Recording starts X minutes before/after official start; it ends Y minutes before/after official end time. days = format_days(meeting['days']) start_time = _adjust_time(meeting['startTime'], app.config['KALTURA_RECORDING_OFFSET_START']) end_time = _adjust_time(meeting['endTime'], app.config['KALTURA_RECORDING_OFFSET_END']) app.logger.info(f""" Prepare to schedule recordings for {course_label}: Room: {room.location} Instructor UIDs: {[instructor['uid'] for instructor in instructors]} Schedule: {days}, {start_time} to {end_time} Recording: {recording_type}; {publish_type} """) term_name = term_name_for_sis_id(term_id) recording_start_date = get_recording_start_date( meeting, return_today_if_past_start=True) recording_end_date = get_recording_end_date(meeting) summary = f'{course_label} ({term_name})' app.logger.info(f""" {course_label} ({term_name}) meets in {room.location}, between {start_time.strftime('%H:%M')} and {end_time.strftime('%H:%M')}, on {days}. Recordings of type {recording_type} will be published to {publish_type}. """) first_day_start = get_first_matching_datetime_of_term( meeting_days=days, start_date=recording_start_date, time_hours=start_time.hour, time_minutes=start_time.minute, ) first_day_end = get_first_matching_datetime_of_term( meeting_days=days, start_date=recording_start_date, time_hours=end_time.hour, time_minutes=end_time.minute, ) description = get_series_description(course_label, instructors, term_name) base_entry = self._create_kaltura_base_entry( description=description, instructors=instructors, name=f'{summary} in {room.location}', ) for category_id in category_ids or []: self.add_to_kaltura_category(category_id=category_id, entry_id=base_entry.id) until = datetime.combine( recording_end_date, time(end_time.hour, end_time.minute), tzinfo=default_timezone(), ) recurring_event = KalturaRecordScheduleEvent( # https://developer.kaltura.com/api-docs/General_Objects/Objects/KalturaScheduleEvent classificationType=KalturaScheduleEventClassificationType. PUBLIC_EVENT, comment=f'{summary} in {room.location}', contact=','.join(instructor['uid'] for instructor in instructors), description=description, duration=(end_time - start_time).seconds, endDate=first_day_end.timestamp(), organizer=app.config['KALTURA_EVENT_ORGANIZER'], ownerId=app.config['KALTURA_KMS_OWNER_ID'], partnerId=self.kaltura_partner_id, recurrence=KalturaScheduleEventRecurrence( # https://developer.kaltura.com/api-docs/General_Objects/Objects/KalturaScheduleEventRecurrence byDay=','.join(days), frequency=KalturaScheduleEventRecurrenceFrequency.WEEKLY, # 'interval' is not documented. When scheduling manually, the value was 1 in each individual event. interval=1, name=summary, timeZone='US/Pacific', until=until.timestamp(), weekStartDay=days[0], ), recurrenceType=KalturaScheduleEventRecurrenceType.RECURRING, startDate=first_day_start.timestamp(), status=KalturaScheduleEventStatus.ACTIVE, summary=summary, tags=CREATED_BY_DIABLO_TAG, templateEntryId=base_entry.id, ) return self.kaltura_client.schedule.scheduleEvent.add(recurring_event)