From 3c8eca7c8ed754b45160730432356f022ff0afce Mon Sep 17 00:00:00 2001 From: David Ullmer Date: Sun, 26 Feb 2023 12:27:28 +0100 Subject: [PATCH] Use background color to identify online lecture --- src/main/kotlin/io/ullmer/rapla/Scraper.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/io/ullmer/rapla/Scraper.kt b/src/main/kotlin/io/ullmer/rapla/Scraper.kt index 64acd63..b4b21ad 100644 --- a/src/main/kotlin/io/ullmer/rapla/Scraper.kt +++ b/src/main/kotlin/io/ullmer/rapla/Scraper.kt @@ -34,7 +34,8 @@ class Scraper(url: String?) { val title = getTitleFromElement(element) val resources = getResourcesFromElement(element) - val location = getRoomOrOnline(resources) + val backgroundColor = element.attr("style") + val location = getRoomOrOnline(resources, backgroundColor) val times = getTimesForLectureElement(element) val dayOfTheWeek = element.select("div")[1].text().substring(0, 2) val dateOfLecture = firstDateOfWeek!!.plusDays(numberOfDaysFromMonday(dayOfTheWeek).toLong()) @@ -113,10 +114,13 @@ class Scraper(url: String?) { return lecturer } - private fun getRoomOrOnline(resources: List): String { + private fun getRoomOrOnline(resources: List, backgroundColor: String): String { + // online courses have a different background + if (backgroundColor.contains("#9999ff")) { + return "online" + } + return when (resources.count()) { - // if only one resource, this is always the course; so this is an online course - 1 -> "online" // when two resources, return the one that doesn't contain the course 2 -> resources.first { !it.contains("STG-") } else -> {"???"}