Skip to content
This repository has been archived by the owner on Apr 29, 2023. It is now read-only.

Commit

Permalink
Use background color to identify online lecture
Browse files Browse the repository at this point in the history
  • Loading branch information
daullmer committed Feb 26, 2023
1 parent 83568d5 commit 3c8eca7
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/kotlin/io/ullmer/rapla/Scraper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -113,10 +114,13 @@ class Scraper(url: String?) {
return lecturer
}

private fun getRoomOrOnline(resources: List<String>): String {
private fun getRoomOrOnline(resources: List<String>, 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 -> {"???"}
Expand Down

0 comments on commit 3c8eca7

Please sign in to comment.