mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[API/Edudziennik] Use Regexes instead of Jsoup in first login.
This commit is contained in:
parent
30ee71f4e3
commit
d336531ca8
@ -91,15 +91,16 @@ object Regexes {
|
||||
|
||||
|
||||
|
||||
val EDUDZIENNIK_STUDENT_START_ID by lazy {
|
||||
"""/Students/([\w-_]+?)/start""".toRegex()
|
||||
val EDUDZIENNIK_STUDENTS_START by lazy {
|
||||
"""<li><a href="/Students/([\w-_]+?)/start/">([\w\s]+?)</a>""".toRegex()
|
||||
}
|
||||
val EDUDZIENNIK_ACCOUNT_NAME_START by lazy {
|
||||
"""<span id="user_dn">([\w\s]+?)</span>""".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()
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user