Compare commits

..

No commits in common. "2515e90bea6c513d906841c8a7a018565850e1c0" and "e6f09c11bad3d1453490505ed5e2b6d77676f871" have entirely different histories.

3 changed files with 33 additions and 24 deletions

View File

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

View File

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

View File

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