added a new timetable parser implementation
* added supports for multiple lessons per slot * added support for lessons which take 2 slots
This commit is contained in:
parent
24f920c05f
commit
58eb217ab7
|
@ -183,6 +183,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
|
|||
val jobTTCurrentWeek = doAsync {
|
||||
try {
|
||||
cTimeTableCurrentWeek = timeTableParser.getTimeTable(cCourse.courseLink)
|
||||
timeTableParser.printTimeTableWeek(cTimeTableCurrentWeek)
|
||||
} catch (e: Exception) {
|
||||
|
||||
uiThread {
|
||||
|
|
|
@ -56,8 +56,12 @@ class NotRetardedCalendar {
|
|||
|
||||
}
|
||||
|
||||
data class Lesson(val lessonSubject: String, val lessonTeacher: String, val lessonRoom:String, val lessonRemark: String)
|
||||
|
||||
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 Lesson(val lessonSubject: String, val lessonTeacher: String, val lessonRoom:String, val lessonRemark: String)
|
||||
|
||||
data class TimeTableDay( var timeslot: Array<ArrayList<Lesson>> = Array(6) { ArrayList<Lesson>()})
|
||||
|
||||
data class TimeTable(var day: Array<TimeTableDay> = Array(6) { TimeTableDay() })
|
|
@ -49,7 +49,56 @@ class TimeTableParser {
|
|||
//val week = scheduleHTML.select("h1.timetable-caption").text()
|
||||
//println("$week successful!\n")
|
||||
|
||||
val rows= scheduleHTML.select("table.timetable").select("tr[scope=\"row\"]")
|
||||
var timeTableWeekTEST = TimeTable()
|
||||
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
|
||||
|
||||
row.select("td.lastcol, td[style]").forEach { element ->
|
||||
// elements are now all lessons, including empty ones
|
||||
|
||||
//println("-------------> Element (Day.Timeslot: " + day + "." + rowIndex + "): " + element)
|
||||
//println("Day.Timeslot: " + day + "." + rowIndex + " lesson: " + element.select("div.lesson-subject").text() + ", " + element.select("div.lesson-teacher").text())
|
||||
|
||||
// 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
|
||||
timeTableWeekTEST.day[day].timeslot[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) {
|
||||
timeTableWeekTEST.day[day + 1].timeslot[rowIndex].add(sLesson)
|
||||
}
|
||||
|
||||
} else {
|
||||
timeTableWeekTEST.day[day].timeslot[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 = timeTableWeekTEST.day[day].timeslot[rowIndex].get(index = 0)
|
||||
}
|
||||
|
||||
if(element.hasClass("lastcol")) day++
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
printTimeTableWeekNew(timeTableWeekTEST)
|
||||
|
||||
scheduleHTML.select("table.timetable").select("td.lastcol").forEachIndexed { index, element ->
|
||||
//println("Index: " + index + " lesson: " + element.select("div.lesson-subject").text() + ", " + element.select("div.lesson-teacher").text())
|
||||
timeTableWeek[index % 6][index / 6] = 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())
|
||||
}
|
||||
|
||||
|
@ -86,7 +135,50 @@ class TimeTableParser {
|
|||
for (j in 0..5) print("-".padEnd(26 + (j.toFloat().div(j).toInt()), '-') + "+")
|
||||
println()
|
||||
}
|
||||
println(" \n")
|
||||
}
|
||||
|
||||
fun printTimeTableWeekNew(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.day[j].timeslot[i].size == 0) 1 else timetable.day[j].timeslot[i].size
|
||||
|
||||
for (lesson in timetable.day[j].timeslot[i]) print(lesson.lessonSubject.padEnd(75/ldiff ,' '))
|
||||
if (ldiff == 2) print(" ")
|
||||
print(" | ")
|
||||
}
|
||||
println()
|
||||
|
||||
for (j in 0..5) {
|
||||
val ldiff = if (timetable.day[j].timeslot[i].size == 0) 1 else timetable.day[j].timeslot[i].size
|
||||
|
||||
for (lesson in timetable.day[j].timeslot[i]) print(lesson.lessonTeacher.padEnd(75/ldiff ,' '))
|
||||
if (ldiff == 2) print(" ")
|
||||
print(" | ")
|
||||
}
|
||||
println()
|
||||
|
||||
for (j in 0..5) {
|
||||
val ldiff = if (timetable.day[j].timeslot[i].size == 0) 1 else timetable.day[j].timeslot[i].size
|
||||
|
||||
for (lesson in timetable.day[j].timeslot[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")
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue