Browse Source

fixed wrong lessonID

pull/18/head
Jannik 3 years ago
parent
commit
aa48668af1
  1. 4
      src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt
  2. 3
      src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/MensaParser.kt
  3. 24
      src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt

4
src/main/kotlin/org/mosad/thecitadelofricks/APIController.kt

@ -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/"

3
src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/MensaParser.kt

@ -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()

24
src/main/kotlin/org/mosad/thecitadelofricks/hsoparser/TimetableParser.kt

@ -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()

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close