2019-03-11 20:12:49 +01:00
/ * *
* TheCitadelofRicks
*
* Copyright 2019 < seil0 @mosad . xyz >
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston ,
* MA 02110 - 1301 , USA .
*
* /
package org.mosad.thecitadelofricks.hsoparser
2019-03-12 22:06:04 +01:00
import org.jsoup.Jsoup
2019-03-11 20:12:49 +01:00
import org.mosad.thecitadelofricks.Meal
2019-03-12 22:06:04 +01:00
import org.mosad.thecitadelofricks.MensaWeek
2019-03-11 20:12:49 +01:00
class MensaParser {
/ * *
* returns the mensa menu for the a week
* /
2019-03-12 22:06:04 +01:00
fun getMensaMenu ( menuLink : String ) : MensaWeek {
val mealWeekList = MensaWeek ( )
2019-03-11 20:12:49 +01:00
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 ( )
2019-03-12 22:06:04 +01:00
val parts = ArrayList ( meal . html ( ) . substringBefore ( " <br> \n " ) . replace ( " \n " , " " ) . split ( " <br> " ) )
2019-03-11 20:12:49 +01:00
val additives = meal . select ( " span.show-with-allergenes " ) . text ( )
2019-03-12 22:06:04 +01:00
parts . removeIf { x -> x . isEmpty ( ) || x . isBlank ( ) }
2019-03-11 20:12:49 +01:00
2019-03-12 22:06:04 +01:00
mealWeekList . days [ dayIndex ] . meals . add ( Meal ( strDay , heading , parts , additives ) )
2019-03-11 20:12:49 +01:00
}
}
// Mon to Sat (0 - 5)
2019-03-12 22:06:04 +01:00
//println(mealWeekList.days[4])
2019-03-11 20:12:49 +01:00
return mealWeekList
}
/ * *
* return the link of the menus of the next week
* /
fun getMenuLinkNextWeek ( menuLink : String ) : String {
val menuHTML = Jsoup . connect ( menuLink ) . get ( )
return " https://www.swfr.de " + menuHTML . select ( " #speiseplan-tabs " ) . select ( " a.next-week " ) . attr ( " href " )
}
}