updated all parser & updated build.gradle
this is the first work to get tcor fully workin
This commit is contained in:
36
src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt
Normal file
36
src/main/kotlin/org/mosad/thecitadelofricks/DataTypes.kt
Normal file
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
|
||||
data class Course(val courseLink: String, val courseName: String)
|
||||
|
||||
data class Meal(val day: String, val heading: String, val parts: ArrayList<String>, val additives: String)
|
||||
|
||||
data class MealWeek(val day: Array<ArrayList<Meal>> = Array(7) { ArrayList<Meal>() })
|
||||
|
||||
data class Lesson(val lessonSubject: String, val lessonTeacher: String, val lessonRoom:String, val lessonRemark: String)
|
||||
|
||||
data class TimeTableDay( val timeslots: Array<ArrayList<Lesson>> = Array(6) { ArrayList<Lesson>()})
|
||||
|
||||
data class TimeTable(val days: Array<TimeTableDay> = Array(6) { TimeTableDay() })
|
40
src/main/kotlin/org/mosad/thecitadelofricks/Main.kt
Normal file
40
src/main/kotlin/org/mosad/thecitadelofricks/Main.kt
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
import org.mosad.thecitadelofricks.hsoparser.CourseListParser
|
||||
import org.mosad.thecitadelofricks.hsoparser.TimeTableParser
|
||||
|
||||
fun main() {
|
||||
|
||||
// TESTING AREA
|
||||
val courseLinks = CourseListParser().getCourseLinks()
|
||||
println(courseLinks)
|
||||
|
||||
val timeTableWeek0 = TimeTableParser().getTimeTable("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=5D255C23-BC03-4AA0-9F36-DC6767F3E05D&week=0")
|
||||
|
||||
val timeTableWeek1 = TimeTableParser().getTimeTable("https://www.hs-offenburg.de/index.php?id=6627&class=class&iddV=5D255C23-BC03-4AA0-9F36-DC6767F3E05D&week=1")
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import org.mosad.thecitadelofricks.Course
|
||||
|
||||
class CourseListParser {
|
||||
|
||||
fun getCourseLinks(): ArrayList<Course> {
|
||||
val courseTTLinkList = ArrayList<Course>() // TODO val may cause bugs!
|
||||
val courseHTML = Jsoup.connect("https://www.hs-offenburg.de/studium/vorlesungsplaene/").get()
|
||||
|
||||
courseHTML.select("ul.index-group").select("li.Class").select("a[href]").forEachIndexed { _, element ->
|
||||
courseTTLinkList.add(
|
||||
Course(
|
||||
element.attr("href").replace("http", "https"),
|
||||
element.text()
|
||||
)
|
||||
)
|
||||
}
|
||||
return courseTTLinkList
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import org.mosad.thecitadelofricks.Meal
|
||||
import org.mosad.thecitadelofricks.MealWeek
|
||||
|
||||
class MensaParser {
|
||||
|
||||
/**
|
||||
* returns the mensa menu for the a week
|
||||
*/
|
||||
fun getMensaMenu(menuLink: String): MealWeek {
|
||||
val mealList = ArrayList<Meal>()
|
||||
val mealWeekList = MealWeek()
|
||||
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()
|
||||
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)) {
|
||||
try {
|
||||
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()
|
||||
|
||||
mealList.add(Meal(strDay, heading, parts, additives))
|
||||
} catch (e: Exception) {
|
||||
//println("Oooups! Something went wrong: ${e.printStackTrace()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Mon to Sat (0 - 5)
|
||||
println(mealWeekList.day[4])
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
import org.jsoup.Jsoup
|
||||
import org.mosad.thecitadelofricks.Lesson
|
||||
import org.mosad.thecitadelofricks.TimeTable
|
||||
|
||||
class TimeTableParser {
|
||||
private val days = arrayOf("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
|
||||
|
||||
/**
|
||||
* get the timetable from the given url
|
||||
* the timetable is organised per row not per column;
|
||||
* Mon 1, Tue 1, Wed 1, Thur 1, Fri 1, Sat 1, Mon 2 and so on
|
||||
*/
|
||||
fun getTimeTable(courseTTURL: String): TimeTable {
|
||||
val timeTableWeek = TimeTable()
|
||||
val scheduleHTML = Jsoup.connect(courseTTURL).get()
|
||||
|
||||
//val week = scheduleHTML.select("h1.timetable-caption").text()
|
||||
//println("$week successful!\n")
|
||||
|
||||
val rows = scheduleHTML.select("table.timetable").select("tr[scope=\"row\"]")
|
||||
var sDay = -1
|
||||
var sRow = -1
|
||||
var sLesson = Lesson("", "", "", "")
|
||||
|
||||
// get each row with index, reflects 1 timeslot per day
|
||||
for ((rowIndex, row) in rows.withIndex()) {
|
||||
var day = 0
|
||||
|
||||
// elements are now all lessons, including empty ones
|
||||
row.select("td.lastcol, td[style]").forEach { element ->
|
||||
|
||||
// if there is a lecture with rowspan="2", we need to shift everything by one to the left. This is stupid and ugly there needs to bee an API
|
||||
if ((sDay > -1 && sRow > -1) && (sDay == day && ((sRow + 1) == rowIndex))) {
|
||||
// we found a lecture that is longer than 1 lesson
|
||||
timeTableWeek.days[day].timeslots[rowIndex].add(sLesson) // this just works if there is one lecture per slot
|
||||
|
||||
// adjust the following slot
|
||||
sDay++
|
||||
sLesson = Lesson(
|
||||
element.select("div.lesson-subject").text(),
|
||||
element.select("div.lesson-teacher").text(),
|
||||
element.select("div.lesson-room").text(),
|
||||
element.select("div.lesson-remark").text()
|
||||
)
|
||||
|
||||
// adjust the slot directly as we don't get there anymore
|
||||
if (sDay == 5) {
|
||||
timeTableWeek.days[day + 1].timeslots[rowIndex].add(sLesson)
|
||||
}
|
||||
|
||||
} else {
|
||||
timeTableWeek.days[day].timeslots[rowIndex].add(
|
||||
Lesson(
|
||||
element.select("div.lesson-subject").text(),
|
||||
element.select("div.lesson-teacher").text(),
|
||||
element.select("div.lesson-room").text(),
|
||||
element.select("div.lesson-remark").text()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// we found a lecture with rowspan="2", save day, row and lesson for later adjustment
|
||||
if (element.toString().contains("rowspan=\"2\"")) {
|
||||
sDay = day
|
||||
sRow = rowIndex
|
||||
sLesson = timeTableWeek.days[day].timeslots[rowIndex].get(index = 0)
|
||||
}
|
||||
|
||||
if (element.hasClass("lastcol")) day++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printTimeTableWeek(timeTableWeek)
|
||||
|
||||
return timeTableWeek
|
||||
}
|
||||
|
||||
fun printTimeTableWeek(timetable: TimeTable) {
|
||||
for (j in 0..5) print(days[j].padEnd(75, ' ') + " | ")
|
||||
println()
|
||||
for (j in 0..5) print("-".padEnd(76 + (j.toFloat().div(j).toInt()), '-') + "+")
|
||||
println()
|
||||
|
||||
// the timeslot
|
||||
for (i in 0..5) {
|
||||
|
||||
for (j in 0..5) {
|
||||
val ldiff = if (timetable.days[j].timeslots[i].size == 0) 1 else timetable.days[j].timeslots[i].size
|
||||
|
||||
for (lesson in timetable.days[j].timeslots[i]) print(lesson.lessonSubject.padEnd(75 / ldiff, ' '))
|
||||
if (ldiff == 2) print(" ")
|
||||
print(" | ")
|
||||
}
|
||||
println()
|
||||
|
||||
for (j in 0..5) {
|
||||
val ldiff = if (timetable.days[j].timeslots[i].size == 0) 1 else timetable.days[j].timeslots[i].size
|
||||
|
||||
for (lesson in timetable.days[j].timeslots[i]) print(lesson.lessonTeacher.padEnd(75 / ldiff, ' '))
|
||||
if (ldiff == 2) print(" ")
|
||||
print(" | ")
|
||||
}
|
||||
println()
|
||||
|
||||
for (j in 0..5) {
|
||||
val ldiff = if (timetable.days[j].timeslots[i].size == 0) 1 else timetable.days[j].timeslots[i].size
|
||||
|
||||
for (lesson in timetable.days[j].timeslots[i]) print(lesson.lessonRoom.padEnd(75 / ldiff, ' '))
|
||||
if (ldiff == 2) print(" ")
|
||||
print(" | ")
|
||||
}
|
||||
println()
|
||||
|
||||
for (j in 0..5) print("-".padEnd(76 + (j.toFloat().div(j).toInt()), '-') + "+")
|
||||
println()
|
||||
}
|
||||
|
||||
println(" \n")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user