2018-10-29 13:04:20 +01:00
/ * *
* ProjectLaogai
*
* Copyright 2018 < seil0 @mosad . xyz >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
*
* /
package org.mosad.seil0.projectlaogai.hsoparser
import org.jsoup.Jsoup
class TimeTableParser {
2018-10-29 18:03:20 +01:00
private val days = arrayOf ( " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " )
private var courseTTLinkList = ArrayList < CourseTTLink > ( )
private var timeTableWeek = arrayOf < Array < Lesson > > ( )
2018-10-29 13:04:20 +01:00
init {
// create the timetable array
for ( i in 0. . 5 ) {
var timeTableDay = arrayOf < Lesson > ( )
2018-10-29 18:03:20 +01:00
for ( j in 0. . 5 ) {
2018-10-29 13:04:20 +01:00
timeTableDay += Lesson ( " " , " " , " " , " " )
}
timeTableWeek += timeTableDay
}
}
/ * *
* 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
* /
2018-10-29 18:03:20 +01:00
fun getTimeTable ( courseTTURL : String ) : Array < Array < Lesson > > {
2018-10-29 13:04:20 +01:00
val scheduleHTML = Jsoup . connect ( courseTTURL ) . get ( )
2018-11-07 14:17:33 +01:00
//val week = scheduleHTML.select("h1.timetable-caption").text()
//println("$week successful!\n")
2018-10-29 13:04:20 +01:00
scheduleHTML . select ( " table.timetable " ) . select ( " td.lastcol " ) . forEachIndexed { index , element ->
timeTableWeek [ index % 6 ] [ index / 6 ] = Lesson ( element . select ( " div.lesson-subject " ) . text ( ) , element . select ( " div.lesson-teacher " ) . text ( ) , element . select ( " div.lesson-room " ) . text ( ) , element . select ( " div.lesson-remark " ) . text ( ) )
}
2018-11-07 14:17:33 +01:00
2018-10-29 18:03:20 +01:00
return timeTableWeek
2018-10-29 13:04:20 +01:00
}
/ * *
* parse all courses from the courses site at https : //www.hs-offenburg.de/studium/vorlesungsplaene/
* /
2018-11-01 02:12:43 +01:00
fun getCourseTTLinks ( ) : ArrayList < CourseTTLink > {
2018-10-29 13:04:20 +01:00
val courseHTML = Jsoup . connect ( " https://www.hs-offenburg.de/studium/vorlesungsplaene/ " ) . get ( )
courseHTML . select ( " ul.index-group " ) . select ( " li.Class " ) . select ( " a[href] " ) . forEachIndexed { _ , element ->
courseTTLinkList . add ( CourseTTLink ( element . attr ( " href " ) , element . text ( ) ) )
}
2018-11-01 02:12:43 +01:00
return courseTTLinkList
2018-10-29 13:04:20 +01:00
}
2018-11-18 21:28:43 +01:00
@Suppress ( " unused " )
2018-10-29 13:04:20 +01:00
fun printTimeTableWeek ( timeTableWeek : Array < Array < Lesson > > ) {
for ( j in 0. . 5 ) print ( days [ j ] . padEnd ( 25 , ' ' ) + " | " )
println ( )
for ( j in 0. . 5 ) print ( " - " . padEnd ( 26 + ( j . toFloat ( ) . div ( j ) . toInt ( ) ) , '-' ) + " + " )
println ( )
2018-10-29 18:03:20 +01:00
for ( i in 0. . 5 ) {
2018-10-29 13:04:20 +01:00
for ( j in 0. . 5 ) print ( timeTableWeek [ j ] [ i ] . lessonSubject . padEnd ( 25 , ' ' ) . substring ( 0 , 25 ) + " | " )
println ( )
for ( j in 0. . 5 ) print ( timeTableWeek [ j ] [ i ] . lessonTeacher . padEnd ( 25 , ' ' ) . substring ( 0 , 25 ) + " | " )
println ( )
for ( j in 0. . 5 ) print ( timeTableWeek [ j ] [ i ] . lessonRoom . padEnd ( 25 , ' ' ) . substring ( 0 , 25 ) + " | " )
println ( )
for ( j in 0. . 5 ) print ( " - " . padEnd ( 26 + ( j . toFloat ( ) . div ( j ) . toInt ( ) ) , '-' ) + " + " )
println ( )
}
println ( )
}
}