added spring and a API specific stuff
this commit adds a fully working API wit /courses, /timetable?courseName=[course] and /mensamenu
This commit is contained in:
@ -22,54 +22,36 @@
|
||||
|
||||
package org.mosad.thecitadelofricks.hsoparser
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.Jsoup
|
||||
import org.mosad.thecitadelofricks.Meal
|
||||
import org.mosad.thecitadelofricks.MealWeek
|
||||
import org.mosad.thecitadelofricks.MensaWeek
|
||||
|
||||
class MensaParser {
|
||||
|
||||
/**
|
||||
* returns the mensa menu for the a week
|
||||
*/
|
||||
fun getMensaMenu(menuLink: String): MealWeek {
|
||||
val mealList = ArrayList<Meal>()
|
||||
val mealWeekList = MealWeek()
|
||||
fun getMensaMenu(menuLink: String): MensaWeek {
|
||||
val mealWeekList = MensaWeek()
|
||||
val menuHTML = Jsoup.connect(menuLink).get()
|
||||
|
||||
menuHTML.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan")
|
||||
.forEachIndexed { dayIndex, day ->
|
||||
val strDay = day.select("h3").text()
|
||||
|
||||
|
||||
day.select("div.menu-info").forEachIndexed { mealIndex, meal ->
|
||||
val heading = day.select("h4")[mealIndex].text()
|
||||
val parts = ArrayList(meal.html().substringBefore("<br>\n").replace("<br>", " ").split("\n"))
|
||||
val parts = ArrayList(meal.html().substringBefore("<br>\n").replace("\n", "").split("<br>"))
|
||||
val additives = meal.select("span.show-with-allergenes").text()
|
||||
parts.removeIf { x -> x.isEmpty()|| x.isBlank() }
|
||||
|
||||
mealWeekList.day[dayIndex].add(Meal(strDay, heading, parts, additives))
|
||||
mealWeekList.days[dayIndex].meals.add(Meal(strDay, heading, parts, additives))
|
||||
}
|
||||
|
||||
for (i in 0..(day.select("div.row h4").size - 1)) {
|
||||
try {
|
||||
val heading = day.select("div.row h4")[i].text()
|
||||
val parts = ArrayList<String>(
|
||||
day.select("div.row").select("div.menu-info")[i].html().substringBefore("<span").replace(
|
||||
"<br>",
|
||||
" "
|
||||
).split("\n")
|
||||
)
|
||||
val additives =
|
||||
day.select("div.row").select("div.menu-info")[i].select("span.show-with-allergenes").text()
|
||||
|
||||
mealList.add(Meal(strDay, heading, parts, additives))
|
||||
} catch (e: Exception) {
|
||||
//println("Oooups! Something went wrong: ${e.printStackTrace()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mon to Sat (0 - 5)
|
||||
println(mealWeekList.day[4])
|
||||
//println(mealWeekList.days[4])
|
||||
|
||||
return mealWeekList
|
||||
}
|
||||
|
Reference in New Issue
Block a user