Modified code to remove 'status' field from lecture's table and added 'event_uuid' field. Also refined the 'start_time' field in recordings' table to handle datetime instead of strings. Further, made minor changes in scraping jobs and seeding logic. Implemented these changes to allow lectures to be associated with calendar events and streamlined various fields.
50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
class ScrapePanoptoJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(*args)
|
|
courses = Course.all
|
|
|
|
courses.each do |course|
|
|
self.scrape_course(course)
|
|
end
|
|
end
|
|
|
|
# @param [Course] course
|
|
def scrape_course(course)
|
|
panopto_folder_ids = course.panopto_folders
|
|
panopto_folder_ids.each do |folder_id|
|
|
recording_data = Panopto::list_folder folder_id
|
|
attributes = recording_data.map do |lecture_data|
|
|
{
|
|
title: lecture_data['title'],
|
|
start_time: Time.new(lecture_data['start_time']),
|
|
recording_uuid: lecture_data['panopto_delivery_id'],
|
|
course_id: course.id,
|
|
}
|
|
end
|
|
|
|
created = Recording.insert_all(attributes, unique_by: :recording_uuid, returning: [:id, :title, :course_id, :start_time])
|
|
|
|
created.each do |new_recording_attrs|
|
|
new_recording = Recording.new(new_recording_attrs)
|
|
|
|
# Find existing lecture to associate with this recording
|
|
if (lecture = course.lectures.find_by(
|
|
start_time: new_recording.start_time.beginning_of_hour + 15.minutes,
|
|
recording_id: nil,
|
|
))
|
|
lecture.update!(recording_id: new_recording.id)
|
|
else
|
|
# Else create a new lecture
|
|
Lecture.create!(
|
|
title: new_recording.nice_title,
|
|
start_time: new_recording.start_time,
|
|
course_id: new_recording.course_id,
|
|
recording_id: new_recording.id
|
|
)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|