parse the week number of the year too
This commit is contained in:
@ -23,6 +23,7 @@
|
||||
package org.mosad.thecitadelofricks.hsoparser
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.mosad.thecitadelofricks.Lesson
|
||||
import org.mosad.thecitadelofricks.TimetableWeek
|
||||
|
||||
@ -39,9 +40,6 @@ class TimetableParser {
|
||||
val timetableWeek = TimetableWeek()
|
||||
val scheduleHTML = Jsoup.connect(timetableURL).get() // TODO add a try catch block to cover timeouts
|
||||
|
||||
//val week = scheduleHTML.select("h1.timetable-caption").text()
|
||||
//println("$week successful!\n")
|
||||
|
||||
val rows = scheduleHTML.select("table.timetable").select("tr[scope=\"row\"]")
|
||||
var sDay = -1
|
||||
var sRow = -1
|
||||
@ -105,11 +103,26 @@ class TimetableParser {
|
||||
|
||||
}
|
||||
|
||||
//printTimetableWeek(timetableWeek)
|
||||
|
||||
return timetableWeek
|
||||
}
|
||||
|
||||
/**
|
||||
* get the week number of the year for the timetable
|
||||
* @param timetableURL the URL of the timetable you want to get
|
||||
*/
|
||||
fun getWeekNumberYear(timetableURL: String): Int {
|
||||
return try {
|
||||
parseWeekNumberYear(Jsoup.connect(timetableURL).get())
|
||||
} catch (ex: Exception) {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
fun parseWeekNumberYear(htmlDoc: Document): Int {
|
||||
return htmlDoc.select("h1.timetable-caption").text().substringAfter("- ")
|
||||
.substringBefore(".").replace(" ", "").toInt()
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
/**
|
||||
* print a timetable
|
||||
|
Reference in New Issue
Block a user