Add basic calendar scraping
This commit is contained in:
parent
915ce5112d
commit
83bc134998
2
Gemfile
2
Gemfile
@ -76,4 +76,4 @@ gem "font-awesome-sass"
|
||||
gem "httparty"
|
||||
|
||||
gem "sidekiq"
|
||||
gem "administrate"
|
||||
gem "icalendar"
|
||||
|
||||
37
Gemfile.lock
37
Gemfile.lock
@ -68,14 +68,6 @@ GEM
|
||||
tzinfo (~> 2.0)
|
||||
addressable (2.8.5)
|
||||
public_suffix (>= 2.0.2, < 6.0)
|
||||
administrate (0.19.0)
|
||||
actionpack (>= 5.0)
|
||||
actionview (>= 5.0)
|
||||
activerecord (>= 5.0)
|
||||
jquery-rails (>= 4.0)
|
||||
kaminari (>= 1.0)
|
||||
sassc-rails (~> 2.1)
|
||||
selectize-rails (~> 0.6)
|
||||
bindex (0.8.1)
|
||||
bootsnap (1.16.0)
|
||||
msgpack (~> 1.2)
|
||||
@ -107,6 +99,9 @@ GEM
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (1.14.1)
|
||||
concurrent-ruby (~> 1.0)
|
||||
icalendar (2.9.0)
|
||||
ice_cube (~> 0.16)
|
||||
ice_cube (0.16.4)
|
||||
importmap-rails (1.2.1)
|
||||
actionpack (>= 6.0.0)
|
||||
railties (>= 6.0.0)
|
||||
@ -117,22 +112,6 @@ GEM
|
||||
jbuilder (2.11.5)
|
||||
actionview (>= 5.0.0)
|
||||
activesupport (>= 5.0.0)
|
||||
jquery-rails (4.6.0)
|
||||
rails-dom-testing (>= 1, < 3)
|
||||
railties (>= 4.2.0)
|
||||
thor (>= 0.14, < 2.0)
|
||||
kaminari (1.2.2)
|
||||
activesupport (>= 4.1.0)
|
||||
kaminari-actionview (= 1.2.2)
|
||||
kaminari-activerecord (= 1.2.2)
|
||||
kaminari-core (= 1.2.2)
|
||||
kaminari-actionview (1.2.2)
|
||||
actionview
|
||||
kaminari-core (= 1.2.2)
|
||||
kaminari-activerecord (1.2.2)
|
||||
activerecord
|
||||
kaminari-core (= 1.2.2)
|
||||
kaminari-core (1.2.2)
|
||||
loofah (2.21.3)
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.12.0)
|
||||
@ -211,13 +190,6 @@ GEM
|
||||
rubyzip (2.3.2)
|
||||
sassc (2.4.0)
|
||||
ffi (~> 1.9)
|
||||
sassc-rails (2.1.2)
|
||||
railties (>= 4.0.0)
|
||||
sassc (>= 2.0)
|
||||
sprockets (> 3.0)
|
||||
sprockets-rails
|
||||
tilt
|
||||
selectize-rails (0.12.6)
|
||||
selenium-webdriver (4.10.0)
|
||||
rexml (~> 3.2, >= 3.2.5)
|
||||
rubyzip (>= 1.2.2, < 3.0)
|
||||
@ -240,7 +212,6 @@ GEM
|
||||
tailwindcss-rails (2.0.30-arm64-darwin)
|
||||
railties (>= 6.0.0)
|
||||
thor (1.2.2)
|
||||
tilt (2.2.0)
|
||||
timeout (0.4.0)
|
||||
turbo-rails (1.4.0)
|
||||
actionpack (>= 6.0.0)
|
||||
@ -269,12 +240,12 @@ PLATFORMS
|
||||
arm64-darwin-22
|
||||
|
||||
DEPENDENCIES
|
||||
administrate
|
||||
bootsnap
|
||||
capybara
|
||||
debug
|
||||
font-awesome-sass
|
||||
httparty
|
||||
icalendar
|
||||
importmap-rails
|
||||
jbuilder
|
||||
pg (~> 1.1)
|
||||
|
||||
20
app/jobs/calendar_scraper_job.rb
Normal file
20
app/jobs/calendar_scraper_job.rb
Normal file
@ -0,0 +1,20 @@
|
||||
class CalendarScraperJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(*args)
|
||||
ics_file = HTTParty.get("https://mytimetable.bath.ac.uk/ical?6519757b&group=false&timetable=!MjAyMyFzdHVkZW50c2V0ITRDRjQ5MjlGRTg1M0Q4N0MyMDZENTVDNUQ3QTJFNzk0&eu=amMzMDkxQGJhdGguYWMudWs=&h=MiuDbRiudE_Yf7B25v2SfEuFCtmYGkFb5sAUI3yGmtY=")
|
||||
calendars = Icalendar::Calendar.parse(ics_file)
|
||||
calendar = calendars.first
|
||||
|
||||
calendar.events.each do |event|
|
||||
summary = event.summary
|
||||
match = summary.split('-')
|
||||
|
||||
# Handle odd events we don't care about
|
||||
return if match.length != 2
|
||||
|
||||
unit_code = match[0]
|
||||
short_lecture_title = match[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
7
test/jobs/calendar_scraper_job_test.rb
Normal file
7
test/jobs/calendar_scraper_job_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class CalendarScraperJobTest < ActiveJob::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user