Compare commits

...

3 Commits

Author SHA1 Message Date
2515e90bea
Update MensaParser for new Mensa website 2022-12-19 20:30:53 +01:00
d457627e00
Update jsoup from 1.14.3 to 1.15.3
Version 1.14.3 also included a vulnerability (CVE-2022-36033) that got fixed with 1.15.3.
2022-12-19 20:30:14 +01:00
795ddc516d
Deduplicate default values in StartupController 2022-12-19 20:26:45 +01:00
3 changed files with 24 additions and 33 deletions

View File

@ -16,7 +16,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.jetbrains.kotlin:kotlin-stdlib' implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1'
implementation 'org.jsoup:jsoup:1.14.3' implementation 'org.jsoup:jsoup:1.15.3'
implementation 'com.google.code.gson:gson:2.9.0' implementation 'com.google.code.gson:gson:2.9.0'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'

View File

@ -44,7 +44,7 @@ class StartupController {
var cachetAPIKey = "0" var cachetAPIKey = "0"
var cachetBaseURL = "https://status.mosad.xyz" var cachetBaseURL = "https://status.mosad.xyz"
var courseListURL = "https://www.hs-offenburg.de/studium/vorlesungsplaene/" var courseListURL = "https://www.hs-offenburg.de/studium/vorlesungsplaene/"
var mensaMenuURL = "https://www.swfr.de/essen-trinken/speiseplaene/mensa-offenburg/" var mensaMenuURL = "https://www.swfr.de/essen/mensen-cafes-speiseplaene/mensa-offenburg"
var mensaName = "Offenburg" var mensaName = "Offenburg"
} }
@ -77,29 +77,21 @@ class StartupController {
val properties = Properties() val properties = Properties()
properties.loadFromXML(FileInputStream(fileConfig)) properties.loadFromXML(FileInputStream(fileConfig))
cachetAPIKey = try { try {
properties.getProperty("cachetAPIKey") cachetAPIKey = properties.getProperty("cachetAPIKey")
} catch (ex: Exception) { } catch (_: Exception) {}
"0"
}
cachetBaseURL = try { try {
properties.getProperty("cachetBaseURL") cachetBaseURL = properties.getProperty("cachetBaseURL")
} catch (ex: Exception) { } catch (_: Exception) {}
"https://status.mosad.xyz"
}
mensaMenuURL = try { try {
properties.getProperty("mensaMenuURL") mensaMenuURL = properties.getProperty("mensaMenuURL")
} catch (ex: Exception) { } catch (_: Exception) {}
"https://www.swfr.de/essen-trinken/speiseplaene/mensa-offenburg/"
}
mensaName = try { try {
properties.getProperty("mensaName") mensaName = properties.getProperty("mensaName")
} catch (ex: Exception) { } catch (_: Exception) {}
"Offenburg"
}
} catch (ex: Exception) { } catch (ex: Exception) {
logger.error("error while loading config", ex) logger.error("error while loading config", ex)
@ -111,10 +103,10 @@ class StartupController {
private fun createConfig() = try { private fun createConfig() = try {
val properties = Properties() val properties = Properties()
properties.setProperty("cachetAPIKey", "0") properties.setProperty("cachetAPIKey", cachetAPIKey)
properties.setProperty("cachetBaseURL", "https://status.mosad.xyz") properties.setProperty("cachetBaseURL", cachetBaseURL)
properties.setProperty("mensaMenuURL", "https://www.swfr.de/essen-trinken/speiseplaene/mensa-offenburg/") properties.setProperty("mensaMenuURL", mensaMenuURL)
properties.setProperty("mensaName", "Offenburg") properties.setProperty("mensaName", mensaName)
val outputStream = FileOutputStream(fileConfig) val outputStream = FileOutputStream(fileConfig)
properties.storeToXML(outputStream, "tcor configuration") properties.storeToXML(outputStream, "tcor configuration")

View File

@ -59,14 +59,14 @@ class MensaParser {
val mealWeekList = MensaWeek() val mealWeekList = MensaWeek()
try { try {
htmlDoc.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan") htmlDoc.select("#tabsWeekdaysMenu").select("div.menu-tagesplan")
.forEachIndexed { dayIndex, day -> .forEachIndexed { dayIndex, day ->
val strDay = day.select("h3").text() val strDay = day.select("h3").text()
day.select("div.row").forEachIndexed { _, meal -> day.select("div.menu-tagesplan > div.grid").first()?.select("div.flex-col")?.forEachIndexed { _, meal ->
val heading = meal.select("h4.menu-header").text() val heading = meal.select("h5").text()
val parts = ArrayList(meal.select("div.menu-info").html().substringBefore("<br><span").replace("\n", "").split("<br>")) val parts = ArrayList(meal.select("small.extra-text").html().split("<br>").map { it.trim() })
val additives = meal.select("span.show-with-allergenes").text() val additives = meal.select("small.zusatzsstoffe[x-show=showAllergenes]").text()
parts.removeIf { x -> x.isEmpty() || x.isBlank() } parts.removeIf { x -> x.isEmpty() || x.isBlank() }
mealWeekList.days[dayIndex].meals.add(Meal(strDay, heading, parts, additives)) mealWeekList.days[dayIndex].meals.add(Meal(strDay, heading, parts, additives))
@ -87,8 +87,7 @@ class MensaParser {
*/ */
fun getMenuLinkNextWeek(mensaMenuURL: String): String { fun getMenuLinkNextWeek(mensaMenuURL: String): String {
val menuHTML = Jsoup.connect(mensaMenuURL).get() val menuHTML = Jsoup.connect(mensaMenuURL).get()
return "https://www.swfr.de" + menuHTML.select("div.section-mensa").select("a.next-week").attr("href")
return "https://www.swfr.de" + menuHTML.select("#speiseplan-tabs").select("a.next-week").attr("href")
} }
} }