82 lines
2.7 KiB
Kotlin
82 lines
2.7 KiB
Kotlin
/**
|
|
* ProjectLaogai
|
|
*
|
|
* Copyright 2018 <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.seil0.projectlaogai.hsoparser
|
|
|
|
import org.jsoup.Jsoup
|
|
import java.util.*
|
|
|
|
class MensaParser {
|
|
private var mealList = ArrayList<Meal>()
|
|
|
|
init {
|
|
// do something
|
|
}
|
|
|
|
/**
|
|
* returns the mensa menu for the whole week
|
|
*/
|
|
fun getMensaMenu(): ArrayList<Meal> {
|
|
val menuHTML = Jsoup.connect("https://www.swfr.de/de/essen-trinken/speiseplaene/mensa-offenburg/").get()
|
|
|
|
menuHTML.select("#speiseplan-tabs").select("div.tab-content").select("div.menu-tagesplan").forEachIndexed { _, element ->
|
|
val day = element.select("h3").text()
|
|
for (i in 0 .. (element.select("div.row h4").size - 1)) {
|
|
try {
|
|
val heading = element.select("div.row h4")[i].text()
|
|
val parts = ArrayList<String>(element.select("div.row").select("div.menu-info")[i].html().substringBefore("<span").replace("<br>", "|").split("|"))
|
|
val additives = element.select("div.row").select("div.menu-info")[i].select("span.show-with-allergenes").text()
|
|
|
|
mealList.add(Meal(day, heading, parts, additives))
|
|
} catch (e: Exception) {
|
|
// catch
|
|
}
|
|
}
|
|
}
|
|
|
|
return mealList
|
|
}
|
|
|
|
/**
|
|
* return the mensa menu of a given day (Mon - Sat)
|
|
*/
|
|
fun getMensaMenuDay(mealList: ArrayList<Meal>, day: Int): ArrayList<Meal> {
|
|
val dayMenus = ArrayList<Meal>()
|
|
val strDay: String = when(day) {
|
|
Calendar.MONDAY -> "Mon"
|
|
Calendar.TUESDAY -> "Die"
|
|
Calendar.WEDNESDAY -> "Mit"
|
|
Calendar.THURSDAY -> "Don"
|
|
Calendar.FRIDAY -> "Fre"
|
|
Calendar.SATURDAY -> "Sam"
|
|
else -> "TODAY" //TODO
|
|
}
|
|
|
|
for (meal in mealList) {
|
|
if (meal.day.contains(strDay)) {
|
|
dayMenus.add(meal)
|
|
}
|
|
}
|
|
return dayMenus
|
|
}
|
|
}
|