forked from github/szkolny
[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 {
|
val EDUDZIENNIK_STUDENTS_START by lazy {
|
||||||
"""/Students/([\w-_]+?)/start""".toRegex()
|
"""<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 {
|
val EDUDZIENNIK_SUBJECT_ID by lazy {
|
||||||
"""/Courses/([\w-_]+?)/""".toRegex()
|
"""/Courses/([\w-_]+?)/""".toRegex()
|
||||||
}
|
}
|
||||||
val EDUDZIENNIK_TEACHER_ID by lazy {
|
|
||||||
"""/Teachers/([\w-_]+?)/""".toRegex()
|
|
||||||
}
|
|
||||||
val EDUDZIENNIK_GRADE_ID by lazy {
|
val EDUDZIENNIK_GRADE_ID by lazy {
|
||||||
"""/Grades/([\w-_]+?)/""".toRegex()
|
"""/Grades/([\w-_]+?)/""".toRegex()
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin
|
||||||
|
|
||||||
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.EventBus
|
||||||
import org.jsoup.Jsoup
|
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_ACCOUNT_NAME_START
|
||||||
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_STUDENT_START_ID
|
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.DataEdudziennik
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLoginWeb
|
||||||
@ -28,14 +28,13 @@ class EdudziennikFirstLogin(val data: DataEdudziennik, val onSuccess: () -> Unit
|
|||||||
init {
|
init {
|
||||||
EdudziennikLoginWeb(data) {
|
EdudziennikLoginWeb(data) {
|
||||||
web.webGet(TAG, "") { text ->
|
web.webGet(TAG, "") { text ->
|
||||||
val doc = Jsoup.parse(text)
|
val accountName = EDUDZIENNIK_ACCOUNT_NAME_START.find(text)?.get(1)?.fixName()
|
||||||
val accountName = doc.select("#user_dn").first().text().fixName()
|
|
||||||
|
|
||||||
doc.select("ul ul").first().select("li > a").forEach {
|
EDUDZIENNIK_STUDENTS_START.findAll(text).forEach {
|
||||||
val studentId = EDUDZIENNIK_STUDENT_START_ID.find(it.attr("href"))?.get(1)
|
val studentId = it[1]
|
||||||
if (studentId.isNullOrBlank()) return@forEach
|
val studentName = it[2].fixName()
|
||||||
|
|
||||||
val studentName = it.text().fixName()
|
if (studentId.isBlank() || studentName.isBlank()) return@forEach
|
||||||
|
|
||||||
val profile = Profile()
|
val profile = Profile()
|
||||||
profile.studentNameLong = studentName
|
profile.studentNameLong = studentName
|
||||||
|
Loading…
x
Reference in New Issue
Block a user