clean up APICOntroller & new CacheController

* added a CacheController to hold all cache variables and clean up the APIController
* more consistent naming of variables
* update mensaMenu and courseList only if the request was successful
This commit is contained in:
2019-05-28 12:49:25 +02:00
parent 9efc7fe4b7
commit 754c8cb17b
7 changed files with 221 additions and 170 deletions

View File

@ -34,12 +34,13 @@ class MensaParser {
/**
* returns the mensa menu for a week
* @param menuLink the url to a mensa menu (swfr)
* @param mensaMenuURL the url to a mensa menu (swfr)
* @return the menu plan found at menuURL or null if the request was not successful
*/
fun getMensaMenu(menuLink: String): MensaWeek {
fun getMensaMenu(mensaMenuURL: String): MensaWeek? {
val mealWeekList = MensaWeek()
try {
val menuHTML = Jsoup.connect(menuLink).timeout(15000).get()
val menuHTML = Jsoup.connect(mensaMenuURL).timeout(15000).get()
menuHTML.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan")
.forEachIndexed { dayIndex, day ->
@ -56,9 +57,11 @@ class MensaParser {
}
} catch (ex: SocketTimeoutException) {
logger.warn("timeout from $menuLink, updating on next attempt!")
logger.warn("timeout from $mensaMenuURL, updating on next attempt!")
return null
} catch (gex: Exception) {
logger.error("general MensaParser error", gex)
return null
}
return mealWeekList
@ -66,10 +69,10 @@ class MensaParser {
/**
* return the link of the next weeks menus
* @param menuLink the current weeks menus link
* @param mensaMenuURL the current weeks menus link
*/
fun getMenuLinkNextWeek(menuLink: String): String {
val menuHTML = Jsoup.connect(menuLink).get()
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")
}