@ -33,10 +33,11 @@ class TimetableParser {
* get the timetable from the given url
* the timetable is organised per row not per column ;
* Mon 1 , Tue 1 , Wed 1 , Thur 1 , Fri 1 , Sat 1 , Mon 2 and so on
* @param timetableURL the URL of the timetable you want to get
* /
fun getTimeTable ( courseTT URL: String ) : TimetableWeek {
fun getTimeTable ( timetable URL: String ) : TimetableWeek {
val timetableWeek = TimetableWeek ( )
val scheduleHTML = Jsoup . connect ( courseTT URL) . get ( )
val scheduleHTML = Jsoup . connect ( timetable URL) . get ( )
//val week = scheduleHTML.select("h1.timetable-caption").text()
//println("$week successful!\n")
@ -49,9 +50,10 @@ class TimetableParser {
// get each row with index, reflects 1 timeslot per day
for ( ( rowIndex , row ) in rows . withIndex ( ) ) {
var day = 0
var lessonIndexDay = 0 // the index of the lesson per timeslot
// elements are now all lessons, including empty ones
row . select ( " td.lastcol, td[style] " ) . forEachIndexed { elementIndex , element ->
row . select ( " td.lastcol, td[style] " ) . forEach { element ->
// if there is a lecture with rowspan="2", we need to shift everything by one to the left. This is stupid and ugly there needs to bee an API
if ( ( sDay > - 1 && sRow > - 1 ) && ( sDay == day && ( ( sRow + 1 ) == rowIndex ) ) ) {
@ -61,7 +63,7 @@ class TimetableParser {
// adjust the following slot
sDay ++
sLesson = Lesson (
" $day . $rowIndex . $elementIndex " , // FIXME this is broken!
" $day . $rowIndex . $lessonIndexDay " ,
element . select ( " div.lesson-subject " ) . text ( ) ,
element . select ( " div.lesson-teacher " ) . text ( ) ,
element . select ( " div.lesson-room " ) . text ( ) ,
@ -76,7 +78,7 @@ class TimetableParser {
} else {
timetableWeek . days [ day ] . timeslots [ rowIndex ] . add (
Lesson (
" $day . $rowIndex . $elementIndex " ,
" $day . $rowIndex . $lessonIndexDay " ,
element . select ( " div.lesson-subject " ) . text ( ) ,
element . select ( " div.lesson-teacher " ) . text ( ) ,
element . select ( " div.lesson-room " ) . text ( ) ,
@ -92,7 +94,13 @@ class TimetableParser {
sLesson = timetableWeek . days [ day ] . timeslots [ rowIndex ] . get ( index = 0 )
}
if ( element . hasClass ( " lastcol " ) ) day ++
lessonIndexDay ++
if ( element . hasClass ( " lastcol " ) )
{
day ++
lessonIndexDay = 0
}
}
}
@ -103,6 +111,10 @@ class TimetableParser {
}
@Suppress ( " unused " )
/ * *
* print a timetable
* @param timetable the timetable to print
* /
fun printTimetableWeek ( timetable : TimetableWeek ) {
for ( j in 0. . 5 ) print ( days [ j ] . padEnd ( 75 , ' ' ) + " | " )
println ( )