[API/Edudziennik] Add saving teachers login ids.

This commit is contained in:
Kacper Ziubryniewicz 2019-12-31 12:23:38 +01:00
parent 62d82c88a1
commit 868e529e62
3 changed files with 11 additions and 4 deletions

View File

@ -135,6 +135,9 @@ object Regexes {
val EDUDZIENNIK_HOMEWORK_ID by lazy {
"""/Homework/([\w-_]+?)/""".toRegex()
}
val EDUDZIENNIK_TEACHER_ID by lazy {
"""/Teachers/([\w-_]+?)/""".toRegex()
}
val EDUDZIENNIK_SCHOOL_DETAIL_ID by lazy {
"""<a id="School_detail".*?/School/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)

View File

@ -116,11 +116,13 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
}
}
fun getTeacher(firstName: String, lastName: String): Teacher {
fun getTeacher(firstName: String, lastName: String, longId: String? = null): Teacher {
val name = "$firstName $lastName".fixName()
val id = name.crc32()
return teacherList.singleOrNull { it.id == id } ?: run {
val teacher = Teacher(profileId, id, firstName, lastName)
return teacherList.singleOrNull { it.id == id }?.also {
if (longId != null && it.loginId == null) it.loginId = longId
} ?: run {
val teacher = Teacher(profileId, id, firstName, lastName, longId)
teacherList.put(id, teacher)
teacher
}

View File

@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
import org.jsoup.Jsoup
import pl.szczodrzynski.edziennik.data.api.ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_SUBJECT_ID
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_TEACHER_ID
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
@ -105,9 +106,10 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
val teacherId = if (info.size >= 2) {
val teacherElement = info[1].child(0)
val teacherLongId = EDUDZIENNIK_TEACHER_ID.find(teacherElement.attr("href"))?.get(1)
val teacherName = teacherElement.text().trim()
teacherName.splitName()?.let { (teacherLastName, teacherFirstName) ->
data.getTeacher(teacherFirstName, teacherLastName)
data.getTeacher(teacherFirstName, teacherLastName, teacherLongId)
}?.id ?: -1
} else -1