forked from github/szkolny
[API/Edudziennik] Add start and lucky number endpoint.
This commit is contained in:
parent
ec14ba76c9
commit
21a6e4d8c6
@ -86,6 +86,6 @@ object Regexes {
|
|||||||
|
|
||||||
|
|
||||||
val EDUDZIENNIK_STUDENT_ID by lazy {
|
val EDUDZIENNIK_STUDENT_ID by lazy {
|
||||||
"""""".toRegex()
|
"""/Students/(\w+?)/""".toRegex()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,10 +48,10 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
|||||||
get() { mSchoolId = mSchoolId ?: profile?.getStudentData("schoolId", null); return mSchoolId }
|
get() { mSchoolId = mSchoolId ?: profile?.getStudentData("schoolId", null); return mSchoolId }
|
||||||
set(value) { profile?.putStudentData("schoolId", value) ?: return; mSchoolId = value }
|
set(value) { profile?.putStudentData("schoolId", value) ?: return; mSchoolId = value }
|
||||||
|
|
||||||
private var mCourseId: String? = null
|
private var mClassId: String? = null
|
||||||
var courseId: String?
|
var classId: String?
|
||||||
get() { mCourseId = mCourseId ?: profile?.getStudentData("courseId", null); return mCourseId }
|
get() { mClassId = mClassId ?: profile?.getStudentData("classId", null); return mClassId }
|
||||||
set(value) { profile?.putStudentData("courseId", value) ?: return; mCourseId = value }
|
set(value) { profile?.putStudentData("classId", value) ?: return; mClassId = value }
|
||||||
|
|
||||||
/* __ __ _
|
/* __ __ _
|
||||||
\ \ / / | |
|
\ \ / / | |
|
||||||
@ -75,6 +75,12 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
|||||||
val schoolEndpoint: String
|
val schoolEndpoint: String
|
||||||
get() = "Schools/$schoolId/"
|
get() = "Schools/$schoolId/"
|
||||||
|
|
||||||
|
val schoolClassEndpoint: String
|
||||||
|
get() = "Schools/$classId/"
|
||||||
|
|
||||||
|
val studentAndClassEndpoint: String
|
||||||
|
get() = "Students/$studentId/Klass/$classId/"
|
||||||
|
|
||||||
val courseEndpoint: String
|
val courseEndpoint: String
|
||||||
get() = "Schools/$courseId/"
|
get() = "Course/$studentId/"
|
||||||
}
|
}
|
||||||
|
@ -4,21 +4,21 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik
|
||||||
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.*
|
import pl.szczodrzynski.edziennik.data.api.FEATURE_LUCKY_NUMBER
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.FEATURE_STUDENT_INFO
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.LOGIN_TYPE_EDUDZIENNIK
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.Feature
|
import pl.szczodrzynski.edziennik.data.api.models.Feature
|
||||||
|
|
||||||
const val ENDPOINT_TEMPLATE_WEB_SAMPLE = 9991
|
const val ENDPOINT_EDUDZIENNIK_WEB_START = 1000
|
||||||
const val ENDPOINT_TEMPLATE_WEB_SAMPLE_2 = 9992
|
const val ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER = 1010
|
||||||
const val ENDPOINT_TEMPLATE_API_SAMPLE = 9993
|
|
||||||
|
|
||||||
val EdudziennikFeatures = listOf(
|
val EdudziennikFeatures = listOf(
|
||||||
Feature(LOGIN_TYPE_TEMPLATE, FEATURE_STUDENT_INFO, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_STUDENT_INFO, listOf(
|
||||||
ENDPOINT_TEMPLATE_WEB_SAMPLE to LOGIN_METHOD_TEMPLATE_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_START to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_TEMPLATE_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
Feature(LOGIN_TYPE_TEMPLATE, FEATURE_SCHOOL_INFO, listOf(
|
|
||||||
ENDPOINT_TEMPLATE_WEB_SAMPLE_2 to LOGIN_METHOD_TEMPLATE_WEB
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_LUCKY_NUMBER, listOf(
|
||||||
), listOf(LOGIN_METHOD_TEMPLATE_WEB)),
|
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
Feature(LOGIN_TYPE_TEMPLATE, FEATURE_GRADES, listOf(
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB))
|
||||||
ENDPOINT_TEMPLATE_API_SAMPLE to LOGIN_METHOD_TEMPLATE_API
|
|
||||||
), listOf(LOGIN_METHOD_TEMPLATE_API))
|
|
||||||
)
|
)
|
||||||
|
@ -4,7 +4,12 @@
|
|||||||
|
|
||||||
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.R
|
||||||
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.ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_START
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web.EdudziennikWebLuckyNumber
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web.EdudziennikWebStart
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
|
|
||||||
class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) {
|
class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) {
|
||||||
@ -34,7 +39,14 @@ class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) {
|
|||||||
private fun useEndpoint(endpointId: Int, onSuccess: () -> Unit) {
|
private fun useEndpoint(endpointId: Int, onSuccess: () -> Unit) {
|
||||||
Utils.d(TAG, "Using endpoint $endpointId")
|
Utils.d(TAG, "Using endpoint $endpointId")
|
||||||
when (endpointId) {
|
when (endpointId) {
|
||||||
// TODO
|
ENDPOINT_EDUDZIENNIK_WEB_START -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_data)
|
||||||
|
EdudziennikWebStart(data, onSuccess)
|
||||||
|
}
|
||||||
|
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||||
|
EdudziennikWebLuckyNumber(data, onSuccess)
|
||||||
|
}
|
||||||
else -> onSuccess()
|
else -> onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
|||||||
val profile
|
val profile
|
||||||
get() = data.profile
|
get() = data.profile
|
||||||
|
|
||||||
fun webGet(tag: String, endpoint: String, onSuccess: (text: String) -> Unit) {
|
fun webGet(tag: String, endpoint: String, xhr: Boolean = false, onSuccess: (text: String) -> Unit) {
|
||||||
val url = "https://dziennikel.appspot.com/" + when (endpoint.endsWith('/') || endpoint.isEmpty()) {
|
val url = "https://dziennikel.appspot.com/" + when (endpoint.endsWith('/') || endpoint.isEmpty()) {
|
||||||
true -> endpoint
|
true -> endpoint
|
||||||
else -> "$endpoint/"
|
else -> "$endpoint/"
|
||||||
@ -68,6 +68,9 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
|||||||
Request.builder()
|
Request.builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.userAgent(EDUDZIENNIK_USER_AGENT)
|
.userAgent(EDUDZIENNIK_USER_AGENT)
|
||||||
|
.apply {
|
||||||
|
if (xhr) header("X-Requested-With", "XMLHttpRequest")
|
||||||
|
}
|
||||||
.get()
|
.get()
|
||||||
.callback(callback)
|
.callback(callback)
|
||||||
.build()
|
.build()
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-23
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.luckynumber.LuckyNumber
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class EdudziennikWebLuckyNumber(override val data: DataEdudziennik,
|
||||||
|
val onSuccess: () -> Unit) : EdudziennikWeb(data) {
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "EdudziennikWebLuckyNumber"
|
||||||
|
}
|
||||||
|
|
||||||
|
init { data.profile?.also { profile ->
|
||||||
|
webGet(TAG, data.schoolEndpoint + "Lucky", xhr = true) { text ->
|
||||||
|
val luckyNumber = text.toInt()
|
||||||
|
|
||||||
|
val luckyNumberObject = LuckyNumber(
|
||||||
|
profileId,
|
||||||
|
Date.getToday(),
|
||||||
|
luckyNumber
|
||||||
|
)
|
||||||
|
|
||||||
|
data.luckyNumberList.add(luckyNumberObject)
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_LUCKY_NUMBER,
|
||||||
|
luckyNumberObject.date.value.toLong(),
|
||||||
|
profile.empty,
|
||||||
|
profile.empty,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
))
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
} ?: onSuccess() }
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-23
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_START
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.get
|
||||||
|
|
||||||
|
class EdudziennikWebStart(override val data: DataEdudziennik,
|
||||||
|
val onSuccess: () -> Unit) : EdudziennikWeb(data) {
|
||||||
|
companion object {
|
||||||
|
private const val TAG = "EdudziennikWebStart"
|
||||||
|
}
|
||||||
|
|
||||||
|
init { data.profile?.also { profile ->
|
||||||
|
webGet(TAG, data.studentEndpoint + "start") { text ->
|
||||||
|
val schoolId = """<a id="School_detail".*?href="/Students/${data.studentId}/School/(\w+?)/""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||||
|
.find(text)?.get(1)
|
||||||
|
|
||||||
|
data.schoolId = schoolId
|
||||||
|
|
||||||
|
val classId = """<a id="Klass_detail".*?href="/Students/${data.studentId}/Klass/(\w+?)/""".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||||
|
.find(text)?.get(1)
|
||||||
|
|
||||||
|
data.classId = classId
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_START, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
} ?: onSuccess() }
|
||||||
|
}
|
@ -33,6 +33,8 @@ class EdudziennikFirstLogin(val data: DataEdudziennik, val onSuccess: () -> Unit
|
|||||||
|
|
||||||
doc.select("ul ul > li").first().children().forEach {
|
doc.select("ul ul > li").first().children().forEach {
|
||||||
val studentId = EDUDZIENNIK_STUDENT_ID.find(it.attr("href"))?.get(1)
|
val studentId = EDUDZIENNIK_STUDENT_ID.find(it.attr("href"))?.get(1)
|
||||||
|
if (studentId.isNullOrBlank()) return@forEach
|
||||||
|
|
||||||
val studentName = it.text().fixName()
|
val studentName = it.text().fixName()
|
||||||
|
|
||||||
val profile = Profile()
|
val profile = Profile()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user