Scraping work
This commit is contained in:
parent
0e0c6694ac
commit
0d97b5fdc0
30
app/jobs/scrape_panopto_job.rb
Normal file
30
app/jobs/scrape_panopto_job.rb
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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|
|
||||||
|
lectures_data = Panopto::list_folder folder_id
|
||||||
|
attributes = lectures_data.map do |lecture_data|
|
||||||
|
{
|
||||||
|
title: lecture_data['title'],
|
||||||
|
start_time: Time.new(lecture_data['start_time']),
|
||||||
|
recording_id: lecture_data['panopto_delivery_id'],
|
||||||
|
course_id: course.id,
|
||||||
|
status: :undetermined
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
Lecture.insert_all(attributes, unique_by: :recording_id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/lib/panopto.rbs
Normal file
3
app/lib/panopto.rbs
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module Panopto
|
||||||
|
def self.list_folder: (folder_id: String) -> Array[Hash[String, untyped]]
|
||||||
|
end
|
||||||
@ -2,12 +2,13 @@ class Lecture < ApplicationRecord
|
|||||||
belongs_to :course
|
belongs_to :course
|
||||||
|
|
||||||
enum :status, [
|
enum :status, [
|
||||||
|
:undetermined,
|
||||||
:future,
|
:future,
|
||||||
:happening_now,
|
:happening_now,
|
||||||
:attended_in_person,
|
:attended_in_person,
|
||||||
:watched_recording,
|
:watched_recording,
|
||||||
:missed,
|
:missed,
|
||||||
]
|
], default: :undetermined
|
||||||
|
|
||||||
def week_number
|
def week_number
|
||||||
((start_time.beginning_of_week - Time.new('2023-10-02')) / 1.week).floor
|
((start_time.beginning_of_week - Time.new('2023-10-02')) / 1.week).floor
|
||||||
@ -22,4 +23,14 @@ class Lecture < ApplicationRecord
|
|||||||
|
|
||||||
"https://uniofbath.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=#{recording_id}"
|
"https://uniofbath.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=#{recording_id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nice_title
|
||||||
|
if course.title == "General Relativity"
|
||||||
|
regex = /.+L(\d+).*/
|
||||||
|
lecture_number = self.title.match(regex)[1].to_i
|
||||||
|
return "Lecture #{lecture_number}"
|
||||||
|
end
|
||||||
|
|
||||||
|
title
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody class="divide-y divide-gray-200 bg-white">
|
<tbody class="divide-y divide-gray-200 bg-white">
|
||||||
|
|
||||||
<% course.lectures.group_by { |lecture| lecture.week_number }.each do |(week_number, lectures)| %>
|
<% course.lectures.order(:start_time).group_by { |lecture| lecture.week_number }.each do |(week_number, lectures)| %>
|
||||||
<tr class="border-t border-gray-200">
|
<tr class="border-t border-gray-200">
|
||||||
<th colspan="4" scope="colgroup" class="bg-gray-50 py-2 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Week <%= week_number %></th>
|
<th colspan="4" scope="colgroup" class="bg-gray-50 py-2 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-6">Week <%= week_number %></th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -27,7 +27,7 @@
|
|||||||
<% lectures.each do |lecture| %>
|
<% lectures.each do |lecture| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
|
<td class="whitespace-nowrap py-4 pl-4 pr-3 text-sm font-medium text-gray-900 sm:pl-6">
|
||||||
<%= lecture.title %>
|
<%= lecture.nice_title %>
|
||||||
</td>
|
</td>
|
||||||
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
<td class="whitespace-nowrap px-3 py-4 text-sm text-gray-500">
|
||||||
<%= lecture.start_time.to_fs(:dmy) %>
|
<%= lecture.start_time.to_fs(:dmy) %>
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
class AddDefaultStatusToLecture < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
change_column :lectures, :status, :integer, default: 0, null: false
|
||||||
|
end
|
||||||
|
end
|
||||||
4
db/schema.rb
generated
4
db/schema.rb
generated
@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.0].define(version: 2023_09_29_181725) do
|
ActiveRecord::Schema[7.0].define(version: 2023_09_29_184126) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_09_29_181725) do
|
|||||||
create_table "lectures", force: :cascade do |t|
|
create_table "lectures", force: :cascade do |t|
|
||||||
t.string "title", null: false
|
t.string "title", null: false
|
||||||
t.datetime "start_time", null: false
|
t.datetime "start_time", null: false
|
||||||
t.integer "status", null: false
|
t.integer "status", default: 0, null: false
|
||||||
t.string "recording_id", null: false
|
t.string "recording_id", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
|||||||
7
test/jobs/scrape_panopto_job_test.rb
Normal file
7
test/jobs/scrape_panopto_job_test.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class ScrapePanoptoJobTest < ActiveJob::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
||||||
Loading…
Reference in New Issue
Block a user