TimetableParser: parse year
All checks were successful
continuous-integration/woodpecker the build was successful

This also adds the parsed year to the meta object included in the timetable response
This commit is contained in:
2021-10-23 23:39:18 +02:00
parent dc57a0d0c1
commit d863f4fb1e
4 changed files with 21 additions and 11 deletions

View File

@ -26,6 +26,7 @@ import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Semaphore
import org.jsoup.Jsoup
import org.jsoup.nodes.Document
import org.mosad.thecitadelofricks.CalendarWeek
import org.mosad.thecitadelofricks.Lesson
import org.mosad.thecitadelofricks.TimetableWeek
import org.slf4j.LoggerFactory
@ -131,11 +132,13 @@ class TimetableParser(timetableURL: String? = null, htmlDoc: Document? = null) {
}
/**
* parse the week number of the year for the timetable
* parse the calendar week and the associated year for the timetable
*/
fun parseWeekNumberYear(): Int? = htmlDoc?.let {
it.select("h1.timetable-caption").text().substringAfter("- ")
.substringBefore(".").replace(" ", "").toInt()
fun parseCalendarWeek(): CalendarWeek? = htmlDoc?.let {
val dateStr = it.select("h1.timetable-caption").text().substringAfter("- ")
val week = dateStr.substringBefore(".").replace(" ", "").toInt()
val year = dateStr.substringAfter("Woche ").replace(" ", "").toInt()
CalendarWeek(week, year)
}
@Suppress("unused")