fixed wrong lessonID

This commit is contained in:
Jannik 2019-04-06 11:33:21 +02:00
parent a3a705d1d7
commit aa48668af1
3 changed files with 22 additions and 9 deletions

View File

@ -48,8 +48,8 @@ class APIController {
var logger: Logger = LoggerFactory.getLogger(APIController::class.java)
private var requestCount = 0
private val startTime = System.currentTimeMillis() / 1000
private val softwareVersion = "1.0.2"
private val apiVersion = "1.0.1"
private val softwareVersion = "1.0.3"
private val apiVersion = "1.0.2"
// hso parser links (hardcoded)
private val mensaLink = "https://www.swfr.de/de/essen-trinken/speiseplaene/mensa-offenburg/"

View File

@ -54,7 +54,8 @@ class MensaParser {
}
/**
* return the link of the menus of the next week
* return the link of the next weeks menus
* @param menuLink the current weeks menus link
*/
fun getMenuLinkNextWeek(menuLink: String): String {
val menuHTML = Jsoup.connect(menuLink).get()

View File

@ -33,10 +33,11 @@ class TimetableParser {
* 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
* @param timetableURL the URL of the timetable you want to get
*/
fun getTimeTable(courseTTURL: String): TimetableWeek {
fun getTimeTable(timetableURL: String): TimetableWeek {
val timetableWeek = TimetableWeek()
val scheduleHTML = Jsoup.connect(courseTTURL).get()
val scheduleHTML = Jsoup.connect(timetableURL).get()
//val week = scheduleHTML.select("h1.timetable-caption").text()
//println("$week successful!\n")
@ -49,9 +50,10 @@ class TimetableParser {
// get each row with index, reflects 1 timeslot per day
for ((rowIndex, row) in rows.withIndex()) {
var day = 0
var lessonIndexDay = 0 // the index of the lesson per timeslot
// elements are now all lessons, including empty ones
row.select("td.lastcol, td[style]").forEachIndexed { elementIndex, element ->
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))) {
@ -61,7 +63,7 @@ class TimetableParser {
// adjust the following slot
sDay++
sLesson = Lesson(
"$day.$rowIndex.$elementIndex", // FIXME this is broken!
"$day.$rowIndex.$lessonIndexDay",
element.select("div.lesson-subject").text(),
element.select("div.lesson-teacher").text(),
element.select("div.lesson-room").text(),
@ -76,7 +78,7 @@ class TimetableParser {
} else {
timetableWeek.days[day].timeslots[rowIndex].add(
Lesson(
"$day.$rowIndex.$elementIndex",
"$day.$rowIndex.$lessonIndexDay",
element.select("div.lesson-subject").text(),
element.select("div.lesson-teacher").text(),
element.select("div.lesson-room").text(),
@ -92,7 +94,13 @@ class TimetableParser {
sLesson = timetableWeek.days[day].timeslots[rowIndex].get(index = 0)
}
if (element.hasClass("lastcol")) day++
lessonIndexDay++
if (element.hasClass("lastcol"))
{
day++
lessonIndexDay = 0
}
}
}
@ -103,6 +111,10 @@ class TimetableParser {
}
@Suppress("unused")
/**
* print a timetable
* @param timetable the timetable to print
*/
fun printTimetableWeek(timetable: TimetableWeek) {
for (j in 0..5) print(days[j].padEnd(75, ' ') + " | ")
println()