2018-10-29 13:04:20 +01:00
/ * *
* ProjectLaogai
*
2019-01-03 13:46:09 +01:00
* Copyright 2019 < seil0 @mosad . xyz >
2018-10-29 13:04:20 +01:00
*
* 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.seil0.projectlaogai.hsoparser
import org.jsoup.Jsoup
import java.util.*
2019-03-10 13:37:13 +01:00
import kotlin.collections.ArrayList
2018-10-29 13:04:20 +01:00
class MensaParser {
/ * *
2019-03-09 22:15:53 +01:00
* returns the mensa menu for the a week
2018-10-29 13:04:20 +01:00
* /
2019-03-10 13:37:13 +01:00
fun getMensaMenu ( menuLink : String ) : MealWeek {
2019-01-04 23:58:54 +01:00
val mealList = ArrayList < Meal > ( )
2019-03-10 13:37:13 +01:00
val mealWeekList = MealWeek ( )
2019-03-09 22:15:53 +01:00
val menuHTML = Jsoup . connect ( menuLink ) . get ( )
2018-10-29 13:04:20 +01:00
2019-03-10 13:37:13 +01:00
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 additives = meal . select ( " span.show-with-allergenes " ) . text ( )
mealWeekList . day [ dayIndex ] . add ( Meal ( strDay , heading , parts , additives ) )
}
for ( i in 0 .. ( day . select ( " div.row h4 " ) . size - 1 ) ) {
2018-10-29 13:04:20 +01:00
try {
2019-03-10 13:37:13 +01:00
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 ( )
2018-10-29 13:04:20 +01:00
2019-03-10 13:37:13 +01:00
mealList . add ( Meal ( strDay , heading , parts , additives ) )
2018-10-29 13:04:20 +01:00
} catch ( e : Exception ) {
2019-03-09 22:15:53 +01:00
//println("Oooups! Something went wrong: ${e.printStackTrace()}")
2018-10-29 13:04:20 +01:00
}
}
}
2018-11-26 11:17:07 +01:00
2019-03-10 13:37:13 +01:00
// Mon to Sat (0 - 5)
//println(mealWeekList.day[4])
return mealWeekList
2018-10-29 13:04:20 +01:00
}
2019-03-09 22:15:53 +01:00
/ * *
* 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 " )
}
2018-10-29 13:04:20 +01:00
}