[API/Edudziennik] Fix getting teacher in timetable and fix getting team name.

This commit is contained in:
Kacper Ziubryniewicz 2019-12-24 15:52:15 +01:00
parent 60ad2e81f3
commit f165ee32e5
2 changed files with 10 additions and 8 deletions

View File

@ -133,6 +133,6 @@ object Regexes {
"""<a id="Klass_detail".*?/Klass/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)
}
val EDUDZIENNIK_CLASS_DETAIL_NAME by lazy {
"""<a id="Klass_detail".*?>Klasa (.*?)</a>""".toRegex(DOT_MATCHES_ALL)
"""<a id="Klass_detail".*?>(.*?)</a>""".toRegex(DOT_MATCHES_ALL)
}
}

View File

@ -82,7 +82,7 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
val course = lesson.select(".course").firstOrNull() ?: return@forEachIndexed
val info = course.select("span > span")
if (info.size < 2) return@forEachIndexed
if (info.isEmpty()) return@forEachIndexed
val type = when (course.hasClass("substitute")) {
true -> Lesson.TYPE_CHANGE
@ -99,11 +99,13 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
/* Getting teacher */
val teacherElement = info[1].child(0)
val teacherName = teacherElement.text().trim()
val teacher = teacherName.splitName()?.let { (teacherLastName, teacherFirstName) ->
data.getTeacher(teacherFirstName, teacherLastName)
} ?: return@forEachIndexed
val teacherId = if (info.size >= 2) {
val teacherElement = info[1].child(0)
val teacherName = teacherElement.text().trim()
teacherName.splitName()?.let { (teacherLastName, teacherFirstName) ->
data.getTeacher(teacherFirstName, teacherLastName)
}?.id ?: -1
} else -1
val lessonObject = Lesson(profileId, -1).also {
it.type = type
@ -112,7 +114,7 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
it.startTime = startTime
it.endTime = endTime
it.subjectId = subject.id
it.teacherId = teacher.id
it.teacherId = teacherId
it.id = it.buildId()
}