Update MensaParser for new Mensa website

This commit is contained in:
Hannes Braun 2022-12-19 20:30:53 +01:00
parent d457627e00
commit 2515e90bea
Signed by: hannesbraun
GPG Key ID: 7B6557E1DFD685BE
2 changed files with 7 additions and 8 deletions

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-trinken/speiseplaene/mensa-offenburg/"
var mensaMenuURL = "https://www.swfr.de/essen/mensen-cafes-speiseplaene/mensa-offenburg"
var mensaName = "Offenburg"
}

View File

@ -59,14 +59,14 @@ class MensaParser {
val mealWeekList = MensaWeek()
try {
htmlDoc.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan")
htmlDoc.select("#tabsWeekdaysMenu").select("div.menu-tagesplan")
.forEachIndexed { dayIndex, day ->
val strDay = day.select("h3").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()
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()
parts.removeIf { x -> x.isEmpty() || x.isBlank() }
mealWeekList.days[dayIndex].meals.add(Meal(strDay, heading, parts, additives))
@ -87,8 +87,7 @@ class MensaParser {
*/
fun getMenuLinkNextWeek(mensaMenuURL: String): String {
val menuHTML = Jsoup.connect(mensaMenuURL).get()
return "https://www.swfr.de" + menuHTML.select("#speiseplan-tabs").select("a.next-week").attr("href")
return "https://www.swfr.de" + menuHTML.select("div.section-mensa").select("a.next-week").attr("href")
}
}