mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 05:48:19 +01:00
[APIv2/Librus] Parse document in LibrusSynergia instead of endpoints
This commit is contained in:
parent
35ed31f6b9
commit
5166228915
@ -38,11 +38,11 @@ const val LIBRUS_API_CLIENT_ID_JST = "49"
|
|||||||
const val LIBRUS_JST_DEMO_CODE = "68656A21"
|
const val LIBRUS_JST_DEMO_CODE = "68656A21"
|
||||||
const val LIBRUS_JST_DEMO_PIN = "1290"
|
const val LIBRUS_JST_DEMO_PIN = "1290"
|
||||||
|
|
||||||
const val LIBRUS_SYNERGIA_URL = "https://synergia.librus.pl/"
|
const val LIBRUS_SYNERGIA_URL = "https://synergia.librus.pl"
|
||||||
/** https://synergia.librus.pl/loguj/token/TOKEN/przenies */
|
/** https://synergia.librus.pl/loguj/token/TOKEN/przenies */
|
||||||
const val LIBRUS_SYNERGIA_TOKEN_LOGIN_URL = "https://synergia.librus.pl/loguj/token/TOKEN/przenies"
|
const val LIBRUS_SYNERGIA_TOKEN_LOGIN_URL = "https://synergia.librus.pl/loguj/token/TOKEN/przenies"
|
||||||
|
|
||||||
const val LIBRUS_MESSAGES_URL = "https://wiadomosci.librus.pl/module/"
|
const val LIBRUS_MESSAGES_URL = "https://wiadomosci.librus.pl/module"
|
||||||
const val LIBRUS_SANDBOX_URL = "https://sandbox.librus.pl/index.php?action="
|
const val LIBRUS_SANDBOX_URL = "https://sandbox.librus.pl/index.php?action="
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@ import im.wangchao.mhttp.Request
|
|||||||
import im.wangchao.mhttp.Response
|
import im.wangchao.mhttp.Response
|
||||||
import im.wangchao.mhttp.callback.TextCallbackHandler
|
import im.wangchao.mhttp.callback.TextCallbackHandler
|
||||||
import okhttp3.Cookie
|
import okhttp3.Cookie
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
import org.jsoup.nodes.Document
|
||||||
import pl.szczodrzynski.edziennik.api.v2.*
|
import pl.szczodrzynski.edziennik.api.v2.*
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||||
@ -25,8 +27,8 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
|||||||
get() = data.profile
|
get() = data.profile
|
||||||
|
|
||||||
fun synergiaGet(tag: String, endpoint: String, method: Int = GET,
|
fun synergiaGet(tag: String, endpoint: String, method: Int = GET,
|
||||||
parameters: Map<String, Any> = emptyMap(), onSuccess: (text: String) -> Unit) {
|
parameters: Map<String, Any> = emptyMap(), onSuccess: (doc: Document) -> Unit) {
|
||||||
d(tag, "Request: Librus/Synergia - $LIBRUS_SYNERGIA_URL$endpoint")
|
d(tag, "Request: Librus/Synergia - $LIBRUS_SYNERGIA_URL/$endpoint")
|
||||||
|
|
||||||
val callback = object : TextCallbackHandler() {
|
val callback = object : TextCallbackHandler() {
|
||||||
override fun onSuccess(text: String?, response: Response?) {
|
override fun onSuccess(text: String?, response: Response?) {
|
||||||
@ -39,7 +41,8 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
|||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
|
|
||||||
try {
|
try {
|
||||||
onSuccess(text)
|
val doc = Jsoup.parse(text)
|
||||||
|
onSuccess(doc)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
data.error(ApiError(tag, EXCEPTION_LIBRUS_SYNERGIA_REQUEST)
|
data.error(ApiError(tag, EXCEPTION_LIBRUS_SYNERGIA_REQUEST)
|
||||||
.withResponse(response)
|
.withResponse(response)
|
||||||
@ -47,6 +50,12 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
|||||||
.withApiResponse(text))
|
.withApiResponse(text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||||
|
data.error(ApiError(tag, ERROR_REQUEST_FAILURE)
|
||||||
|
.withResponse(response)
|
||||||
|
.withThrowable(throwable))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.app.cookieJar.saveFromResponse(null, listOf(
|
data.app.cookieJar.saveFromResponse(null, listOf(
|
||||||
@ -58,7 +67,7 @@ open class LibrusSynergia(open val data: DataLibrus) {
|
|||||||
))
|
))
|
||||||
|
|
||||||
Request.builder()
|
Request.builder()
|
||||||
.url("$LIBRUS_SYNERGIA_URL$endpoint")
|
.url("$LIBRUS_SYNERGIA_URL/$endpoint")
|
||||||
.userAgent(LIBRUS_USER_AGENT)
|
.userAgent(LIBRUS_USER_AGENT)
|
||||||
.apply {
|
.apply {
|
||||||
when (method) {
|
when (method) {
|
||||||
|
@ -1,19 +0,0 @@
|
|||||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.App
|
|
||||||
import pl.szczodrzynski.edziennik.api.v2.models.Data
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.ProgressCallback
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile
|
|
||||||
|
|
||||||
class LibrusSynergiaGrades(val app: App,
|
|
||||||
val profile: Profile,
|
|
||||||
val loginStore: LoginStore,
|
|
||||||
val data: Data,
|
|
||||||
val callback: ProgressCallback,
|
|
||||||
val onSuccess: () -> Unit) {
|
|
||||||
|
|
||||||
init {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
||||||
|
|
||||||
import org.jsoup.Jsoup
|
|
||||||
import pl.szczodrzynski.edziennik.HOUR
|
import pl.szczodrzynski.edziennik.HOUR
|
||||||
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_HOMEWORK
|
import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_HOMEWORK
|
||||||
import pl.szczodrzynski.edziennik.api.v2.POST
|
import pl.szczodrzynski.edziennik.api.v2.POST
|
||||||
@ -32,8 +31,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus, val onSuccess: () ->
|
|||||||
"dataDo" to profile!!.getSemesterEnd(profile?.currentSemester ?: 2).stringY_m_d,
|
"dataDo" to profile!!.getSemesterEnd(profile?.currentSemester ?: 2).stringY_m_d,
|
||||||
"przedmiot" to -1
|
"przedmiot" to -1
|
||||||
|
|
||||||
)) { text ->
|
)) { doc ->
|
||||||
val doc = Jsoup.parse(text)
|
|
||||||
|
|
||||||
doc.select("table.myHomeworkTable > tbody").firstOrNull()?.also { homeworkTable ->
|
doc.select("table.myHomeworkTable > tbody").firstOrNull()?.also { homeworkTable ->
|
||||||
val homeworkElements = homeworkTable.children()
|
val homeworkElements = homeworkTable.children()
|
||||||
@ -93,7 +91,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus, val onSuccess: () ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
// because this requires a synergia login (2 more requests) sync this every two hours or if explicit :D
|
// because this requires a synergia login (2 more requests) sync this every two hours or if explicit :D
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK, 2*HOUR, DRAWER_ITEM_HOMEWORK)
|
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK, 2 * HOUR, DRAWER_ITEM_HOMEWORK)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
||||||
|
|
||||||
import org.jsoup.Jsoup
|
|
||||||
import pl.szczodrzynski.edziennik.MONTH
|
import pl.szczodrzynski.edziennik.MONTH
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_SYNERGIA_INFO
|
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_SYNERGIA_INFO
|
||||||
@ -16,8 +15,7 @@ class LibrusSynergiaInfo(override val data: DataLibrus, val onSuccess: () -> Uni
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
synergiaGet(TAG, "informacja") { text ->
|
synergiaGet(TAG, "informacja") { doc ->
|
||||||
val doc = Jsoup.parse(text)
|
|
||||||
|
|
||||||
doc.select("table.form tbody").firstOrNull()?.children()?.also { info ->
|
doc.select("table.form tbody").firstOrNull()?.children()?.also { info ->
|
||||||
val studentNumber = info[2].select("td").text().trim().toIntOrNull()
|
val studentNumber = info[2].select("td").text().trim().toIntOrNull()
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
package pl.szczodrzynski.edziennik.api.v2.librus.data.synergia
|
||||||
|
|
||||||
import org.jsoup.Jsoup
|
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusSynergia
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusSynergia
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
@ -15,8 +14,7 @@ class LibrusSynergiaTemplate(override val data: DataLibrus, val onSuccess: () ->
|
|||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
/* synergiaGet(TAG, "") { text ->
|
/* synergiaGet(TAG, "") { doc ->
|
||||||
val doc = Jsoup.parse(text)
|
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_LIBRUS_SYNERGIA_, SYNC_ALWAYS)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
|
@ -158,26 +158,26 @@ class DataVulcan(app: App, profile: Profile?, loginStore: LoginStore) : Data(app
|
|||||||
val apiUrl: String?
|
val apiUrl: String?
|
||||||
get() {
|
get() {
|
||||||
val url = when (apiToken?.substring(0, 3)) {
|
val url = when (apiToken?.substring(0, 3)) {
|
||||||
"3S1" -> "https://lekcjaplus.vulcan.net.pl/"
|
"3S1" -> "https://lekcjaplus.vulcan.net.pl"
|
||||||
"TA1" -> "https://uonetplus-komunikacja.umt.tarnow.pl/"
|
"TA1" -> "https://uonetplus-komunikacja.umt.tarnow.pl"
|
||||||
"OP1" -> "https://uonetplus-komunikacja.eszkola.opolskie.pl/"
|
"OP1" -> "https://uonetplus-komunikacja.eszkola.opolskie.pl"
|
||||||
"RZ1" -> "https://uonetplus-komunikacja.resman.pl/"
|
"RZ1" -> "https://uonetplus-komunikacja.resman.pl"
|
||||||
"GD1" -> "https://uonetplus-komunikacja.edu.gdansk.pl/"
|
"GD1" -> "https://uonetplus-komunikacja.edu.gdansk.pl"
|
||||||
"KA1" -> "https://uonetplus-komunikacja.mcuw.katowice.eu/"
|
"KA1" -> "https://uonetplus-komunikacja.mcuw.katowice.eu"
|
||||||
"KA2" -> "https://uonetplus-komunikacja-test.mcuw.katowice.eu/"
|
"KA2" -> "https://uonetplus-komunikacja-test.mcuw.katowice.eu"
|
||||||
"P03" -> "https://efeb-komunikacja-pro-efebmobile.pro.vulcan.pl/"
|
"P03" -> "https://efeb-komunikacja-pro-efebmobile.pro.vulcan.pl"
|
||||||
"P01" -> "http://efeb-komunikacja.pro-hudson.win.vulcan.pl/"
|
"P01" -> "http://efeb-komunikacja.pro-hudson.win.vulcan.pl"
|
||||||
"P02" -> "http://efeb-komunikacja.pro-hudsonrc.win.vulcan.pl/"
|
"P02" -> "http://efeb-komunikacja.pro-hudsonrc.win.vulcan.pl"
|
||||||
"P90" -> "http://efeb-komunikacja-pro-mwujakowska.neo.win.vulcan.pl/"
|
"P90" -> "http://efeb-komunikacja-pro-mwujakowska.neo.win.vulcan.pl"
|
||||||
"FK1", "FS1" -> "http://api.fakelog.cf/"
|
"FK1", "FS1" -> "http://api.fakelog.cf"
|
||||||
"SZ9" -> "http://vulcan.szkolny.eu/"
|
"SZ9" -> "http://vulcan.szkolny.eu"
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
return if (url != null) "$url$symbol/" else null
|
return if (url != null) "$url/$symbol" else null
|
||||||
}
|
}
|
||||||
|
|
||||||
val fullApiUrl: String?
|
val fullApiUrl: String?
|
||||||
get() {
|
get() {
|
||||||
return "${apiUrl}${schoolSymbol}/"
|
return "${apiUrl}/${schoolSymbol}/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user