From d336531ca8866c30abcf44003ffc3386f0cda1cb Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Mon, 23 Dec 2019 23:20:45 +0100 Subject: [PATCH] [API/Edudziennik] Use Regexes instead of Jsoup in first login. --- .../szczodrzynski/edziennik/data/api/Regexes.kt | 11 ++++++----- .../firstlogin/EdudziennikFirstLogin.kt | 15 +++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt index 8b4bef89..07a1d8d6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt @@ -91,15 +91,16 @@ object Regexes { - val EDUDZIENNIK_STUDENT_START_ID by lazy { - """/Students/([\w-_]+?)/start""".toRegex() + val EDUDZIENNIK_STUDENTS_START by lazy { + """
  • ([\w\s]+?)""".toRegex() } + val EDUDZIENNIK_ACCOUNT_NAME_START by lazy { + """([\w\s]+?)""".toRegex() + } + val EDUDZIENNIK_SUBJECT_ID by lazy { """/Courses/([\w-_]+?)/""".toRegex() } - val EDUDZIENNIK_TEACHER_ID by lazy { - """/Teachers/([\w-_]+?)/""".toRegex() - } val EDUDZIENNIK_GRADE_ID by lazy { """/Grades/([\w-_]+?)/""".toRegex() } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/firstlogin/EdudziennikFirstLogin.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/firstlogin/EdudziennikFirstLogin.kt index 0e9c09ac..e9b9156c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/firstlogin/EdudziennikFirstLogin.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/firstlogin/EdudziennikFirstLogin.kt @@ -5,8 +5,8 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin import org.greenrobot.eventbus.EventBus -import org.jsoup.Jsoup -import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_STUDENT_START_ID +import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_ACCOUNT_NAME_START +import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_STUDENTS_START import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb @@ -28,14 +28,13 @@ class EdudziennikFirstLogin(val data: DataEdudziennik, val onSuccess: () -> Unit init { EdudziennikLoginWeb(data) { web.webGet(TAG, "") { text -> - val doc = Jsoup.parse(text) - val accountName = doc.select("#user_dn").first().text().fixName() + val accountName = EDUDZIENNIK_ACCOUNT_NAME_START.find(text)?.get(1)?.fixName() - doc.select("ul ul").first().select("li > a").forEach { - val studentId = EDUDZIENNIK_STUDENT_START_ID.find(it.attr("href"))?.get(1) - if (studentId.isNullOrBlank()) return@forEach + EDUDZIENNIK_STUDENTS_START.findAll(text).forEach { + val studentId = it[1] + val studentName = it[2].fixName() - val studentName = it.text().fixName() + if (studentId.isBlank() || studentName.isBlank()) return@forEach val profile = Profile() profile.studentNameLong = studentName