cover some timeouts
This commit is contained in:
@ -25,30 +25,39 @@ package org.mosad.thecitadelofricks.hsoparser
|
||||
import org.jsoup.Jsoup
|
||||
import org.mosad.thecitadelofricks.Meal
|
||||
import org.mosad.thecitadelofricks.MensaWeek
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.net.SocketTimeoutException
|
||||
|
||||
class MensaParser {
|
||||
|
||||
var logger: org.slf4j.Logger = LoggerFactory.getLogger(MensaParser::class.java)
|
||||
|
||||
/**
|
||||
* returns the mensa menu for the a week
|
||||
* returns the mensa menu for a week
|
||||
* @param menuLink the url to a mensa menu (swfr)
|
||||
*/
|
||||
fun getMensaMenu(menuLink: String): MensaWeek {
|
||||
val mealWeekList = MensaWeek()
|
||||
val menuHTML = Jsoup.connect(menuLink).get()
|
||||
try {
|
||||
val menuHTML = Jsoup.connect(menuLink).timeout(15000).get()
|
||||
|
||||
menuHTML.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan")
|
||||
.forEachIndexed { dayIndex, day ->
|
||||
val strDay = day.select("h3").text()
|
||||
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("\n", "").split("<br>"))
|
||||
val additives = meal.select("span.show-with-allergenes").text()
|
||||
parts.removeIf { x -> x.isEmpty() || x.isBlank() }
|
||||
day.select("div.menu-info").forEachIndexed { mealIndex, meal ->
|
||||
val heading = day.select("h4")[mealIndex].text()
|
||||
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.days[dayIndex].meals.add(Meal(strDay, heading, parts, additives))
|
||||
}
|
||||
|
||||
mealWeekList.days[dayIndex].meals.add(Meal(strDay, heading, parts, additives))
|
||||
}
|
||||
|
||||
}
|
||||
} catch (ex: SocketTimeoutException) {
|
||||
logger.warn("timeout from $menuLink, updating on next attempt!")
|
||||
}
|
||||
|
||||
return mealWeekList
|
||||
}
|
||||
|
Reference in New Issue
Block a user