22 lines
702 B
Ruby
22 lines
702 B
Ruby
class ScrapeCalendarJob < 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]
|
|
start_time = event.dtstart
|
|
end
|
|
end
|
|
end
|