mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-31 13:48:20 +01:00
[API/Edudziennik] Fix downloading timetable out of the school year.
This commit is contained in:
parent
6c81a506e9
commit
39ff47e866
@ -163,6 +163,7 @@ const val ERROR_LOGIN_EDUDZIENNIK_WEB_OTHER = 510
|
|||||||
const val ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID = 511
|
const val ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID = 511
|
||||||
const val ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC = 520
|
const val ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC = 520
|
||||||
const val ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS = 521
|
const val ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS = 521
|
||||||
|
const val ERROR_EDUDZIENNIK_WEB_SESSION_EXPIRED = 522
|
||||||
const val ERROR_EDUDZIENNIK_WEB_TEAM_MISSING = 530
|
const val ERROR_EDUDZIENNIK_WEB_TEAM_MISSING = 530
|
||||||
|
|
||||||
const val ERROR_TEMPLATE_WEB_OTHER = 801
|
const val ERROR_TEMPLATE_WEB_OTHER = 801
|
||||||
|
@ -6,16 +6,13 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik
|
|||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import pl.szczodrzynski.edziennik.App
|
import pl.szczodrzynski.edziennik.App
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC
|
import pl.szczodrzynski.edziennik.data.api.*
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edudziennikLoginMethods
|
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikData
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikData
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin.EdudziennikFirstLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.firstlogin.EdudziennikFirstLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLogin
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.login.EdudziennikLogin
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikCallback
|
||||||
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
import pl.szczodrzynski.edziennik.data.api.interfaces.EdziennikInterface
|
||||||
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
import pl.szczodrzynski.edziennik.data.api.models.ApiError
|
||||||
import pl.szczodrzynski.edziennik.data.api.prepare
|
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.Message
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageFull
|
||||||
@ -131,6 +128,9 @@ class Edudziennik(val app: App, val profile: Profile?, val loginStore: LoginStor
|
|||||||
}
|
}
|
||||||
internalErrorList.add(apiError.errorCode)
|
internalErrorList.add(apiError.errorCode)
|
||||||
when (apiError.errorCode) {
|
when (apiError.errorCode) {
|
||||||
|
ERROR_EDUDZIENNIK_WEB_SESSION_EXPIRED -> {
|
||||||
|
login()
|
||||||
|
}
|
||||||
ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID -> {
|
ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID -> {
|
||||||
login()
|
login()
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,7 @@ open class EdudziennikWeb(open val data: DataEdudziennik) {
|
|||||||
override fun onFailure(response: Response?, throwable: Throwable?) {
|
override fun onFailure(response: Response?, throwable: Throwable?) {
|
||||||
val error = when (response?.code()) {
|
val error = when (response?.code()) {
|
||||||
402 -> ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS
|
402 -> ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS
|
||||||
|
403 -> ERROR_EDUDZIENNIK_WEB_SESSION_EXPIRED
|
||||||
else -> ERROR_REQUEST_FAILURE
|
else -> ERROR_REQUEST_FAILURE
|
||||||
}
|
}
|
||||||
data.error(ApiError(tag, error)
|
data.error(ApiError(tag, error)
|
||||||
|
@ -57,82 +57,87 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
|
|||||||
val table = doc.select("#Schedule tbody").first()
|
val table = doc.select("#Schedule tbody").first()
|
||||||
|
|
||||||
if (table.text().trim() == "Brak planu lekcji.") {
|
if (table.text().trim() == "Brak planu lekcji.") {
|
||||||
data.error(ApiError(TAG, ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC)
|
val today = Date.getToday()
|
||||||
.withApiResponse(text))
|
val schoolYearStart = if (today.month >= 9) today.year else today.year - 1
|
||||||
onSuccess()
|
|
||||||
return@webGet
|
|
||||||
}
|
|
||||||
|
|
||||||
table.children().forEach { row ->
|
if (weekStart >= Date(schoolYearStart, 9, 1)) {
|
||||||
val rowElements = row.children()
|
data.error(ApiError(TAG, ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC)
|
||||||
|
.withApiResponse(text))
|
||||||
val lessonNumber = rowElements[0].text().toInt()
|
onSuccess()
|
||||||
|
return@webGet
|
||||||
val times = rowElements[1].text().split('-')
|
|
||||||
val startTime = Time.fromH_m(times[0].trim())
|
|
||||||
val endTime = Time.fromH_m(times[1].trim())
|
|
||||||
|
|
||||||
data.lessonRanges.singleOrNull {
|
|
||||||
it.lessonNumber == lessonNumber && it.startTime == startTime && it.endTime == endTime
|
|
||||||
} ?: run {
|
|
||||||
data.lessonRanges.put(lessonNumber, LessonRange(profileId, lessonNumber, startTime, endTime))
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
table.children().forEach { row ->
|
||||||
|
val rowElements = row.children()
|
||||||
|
|
||||||
rowElements.subList(2, rowElements.size).forEachIndexed { index, lesson ->
|
val lessonNumber = rowElements[0].text().toInt()
|
||||||
val course = lesson.select(".course").firstOrNull() ?: return@forEachIndexed
|
|
||||||
val info = course.select("span > span")
|
|
||||||
|
|
||||||
if (info.isEmpty()) return@forEachIndexed
|
val times = rowElements[1].text().split('-')
|
||||||
|
val startTime = Time.fromH_m(times[0].trim())
|
||||||
|
val endTime = Time.fromH_m(times[1].trim())
|
||||||
|
|
||||||
val type = when (course.hasClass("substitute")) {
|
data.lessonRanges.singleOrNull {
|
||||||
true -> Lesson.TYPE_CHANGE
|
it.lessonNumber == lessonNumber && it.startTime == startTime && it.endTime == endTime
|
||||||
else -> Lesson.TYPE_NORMAL
|
} ?: run {
|
||||||
|
data.lessonRanges.put(lessonNumber, LessonRange(profileId, lessonNumber, startTime, endTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Getting subject */
|
rowElements.subList(2, rowElements.size).forEachIndexed { index, lesson ->
|
||||||
|
val course = lesson.select(".course").firstOrNull() ?: return@forEachIndexed
|
||||||
|
val info = course.select("span > span")
|
||||||
|
|
||||||
val subjectElement = info[0].child(0)
|
if (info.isEmpty()) return@forEachIndexed
|
||||||
val subjectId = EDUDZIENNIK_SUBJECT_ID.find(subjectElement.attr("href"))?.get(1)
|
|
||||||
?: return@forEachIndexed
|
|
||||||
val subjectName = subjectElement.text().trim()
|
|
||||||
val subject = data.getSubject(subjectId, subjectName)
|
|
||||||
|
|
||||||
/* Getting teacher */
|
val type = when (course.hasClass("substitute")) {
|
||||||
|
true -> Lesson.TYPE_CHANGE
|
||||||
|
else -> Lesson.TYPE_NORMAL
|
||||||
|
}
|
||||||
|
|
||||||
val teacherId = if (info.size >= 2) {
|
/* Getting subject */
|
||||||
val teacherElement = info[1].child(0)
|
|
||||||
val teacherName = teacherElement.text().trim()
|
|
||||||
teacherName.splitName()?.let { (teacherLastName, teacherFirstName) ->
|
|
||||||
data.getTeacher(teacherFirstName, teacherLastName)
|
|
||||||
}?.id ?: -1
|
|
||||||
} else -1
|
|
||||||
|
|
||||||
val lessonObject = Lesson(profileId, -1).also {
|
val subjectElement = info[0].child(0)
|
||||||
it.type = type
|
val subjectId = EDUDZIENNIK_SUBJECT_ID.find(subjectElement.attr("href"))?.get(1)
|
||||||
it.date = weekStart.clone().stepForward(0, 0, index)
|
?: return@forEachIndexed
|
||||||
it.lessonNumber = lessonNumber
|
val subjectName = subjectElement.text().trim()
|
||||||
it.startTime = startTime
|
val subject = data.getSubject(subjectId, subjectName)
|
||||||
it.endTime = endTime
|
|
||||||
it.subjectId = subject.id
|
|
||||||
it.teacherId = teacherId
|
|
||||||
|
|
||||||
it.id = it.buildId()
|
/* Getting teacher */
|
||||||
}
|
|
||||||
|
|
||||||
data.lessonNewList.add(lessonObject)
|
val teacherId = if (info.size >= 2) {
|
||||||
dataDays.remove(lessonObject.date!!.value)
|
val teacherElement = info[1].child(0)
|
||||||
|
val teacherName = teacherElement.text().trim()
|
||||||
|
teacherName.splitName()?.let { (teacherLastName, teacherFirstName) ->
|
||||||
|
data.getTeacher(teacherFirstName, teacherLastName)
|
||||||
|
}?.id ?: -1
|
||||||
|
} else -1
|
||||||
|
|
||||||
if (type != Lesson.TYPE_NORMAL) {
|
val lessonObject = Lesson(profileId, -1).also {
|
||||||
val seen = profile.empty || lessonObject.date!! < Date.getToday()
|
it.type = type
|
||||||
|
it.date = weekStart.clone().stepForward(0, 0, index)
|
||||||
|
it.lessonNumber = lessonNumber
|
||||||
|
it.startTime = startTime
|
||||||
|
it.endTime = endTime
|
||||||
|
it.subjectId = subject.id
|
||||||
|
it.teacherId = teacherId
|
||||||
|
|
||||||
data.metadataList.add(Metadata(
|
it.id = it.buildId()
|
||||||
profileId,
|
}
|
||||||
Metadata.TYPE_LESSON_CHANGE,
|
|
||||||
lessonObject.id,
|
data.lessonNewList.add(lessonObject)
|
||||||
seen,
|
dataDays.remove(lessonObject.date!!.value)
|
||||||
seen,
|
|
||||||
System.currentTimeMillis()
|
if (type != Lesson.TYPE_NORMAL) {
|
||||||
))
|
val seen = profile.empty || lessonObject.date!! < Date.getToday()
|
||||||
|
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_LESSON_CHANGE,
|
||||||
|
lessonObject.id,
|
||||||
|
seen,
|
||||||
|
seen,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
<string name="error_110" translatable="false">ERROR_INVALID_LOGIN_MODE</string>
|
<string name="error_110" translatable="false">ERROR_INVALID_LOGIN_MODE</string>
|
||||||
<string name="error_111" translatable="false">ERROR_LOGIN_METHOD_NOT_SATISFIED</string>
|
<string name="error_111" translatable="false">ERROR_LOGIN_METHOD_NOT_SATISFIED</string>
|
||||||
<string name="error_112" translatable="false">ERROR_NOT_IMPLEMENTED</string>
|
<string name="error_112" translatable="false">ERROR_NOT_IMPLEMENTED</string>
|
||||||
|
<string name="error_113" translatable="false">ERROR_FILE_DOWNLOAD</string>
|
||||||
|
|
||||||
<string name="error_115" translatable="false">ERROR_NO_STUDENTS_IN_ACCOUNT</string>
|
<string name="error_115" translatable="false">ERROR_NO_STUDENTS_IN_ACCOUNT</string>
|
||||||
|
|
||||||
@ -132,6 +133,7 @@
|
|||||||
<string name="error_511" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID</string>
|
<string name="error_511" translatable="false">ERROR_LOGIN_EDUDZIENNIK_WEB_NO_SESSION_ID</string>
|
||||||
<string name="error_520" translatable="false">ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC</string>
|
<string name="error_520" translatable="false">ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC</string>
|
||||||
<string name="error_521" translatable="false">ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS</string>
|
<string name="error_521" translatable="false">ERROR_EDUDZIENNIK_WEB_LIMITED_ACCESS</string>
|
||||||
|
<string name="error_522" translatable="false">ERROR_EDUDZIENNIK_WEB_SESSION_EXPIRED</string>
|
||||||
<string name="error_530" translatable="false">ERROR_EDUDZIENNIK_WEB_TEAM_MISSING</string>
|
<string name="error_530" translatable="false">ERROR_EDUDZIENNIK_WEB_TEAM_MISSING</string>
|
||||||
|
|
||||||
<string name="error_801" translatable="false">ERROR_TEMPLATE_WEB_OTHER</string>
|
<string name="error_801" translatable="false">ERROR_TEMPLATE_WEB_OTHER</string>
|
||||||
@ -168,6 +170,7 @@
|
|||||||
<string name="error_110_reason">Nieprawidłowy sposób logowania</string>
|
<string name="error_110_reason">Nieprawidłowy sposób logowania</string>
|
||||||
<string name="error_111_reason">Nie można wywołać metody logowania</string>
|
<string name="error_111_reason">Nie można wywołać metody logowania</string>
|
||||||
<string name="error_112_reason">Nie zaimplementowano</string>
|
<string name="error_112_reason">Nie zaimplementowano</string>
|
||||||
|
<string name="error_113_reason">Wystąpił błąd podczas pobierania pliku</string>
|
||||||
|
|
||||||
<string name="error_115_reason">Brak uczniów przypisanych do konta</string>
|
<string name="error_115_reason">Brak uczniów przypisanych do konta</string>
|
||||||
|
|
||||||
@ -281,6 +284,7 @@
|
|||||||
<string name="error_511_reason">Brak ID sesji</string>
|
<string name="error_511_reason">Brak ID sesji</string>
|
||||||
<string name="error_520_reason">Plan lekcji niedostępny</string>
|
<string name="error_520_reason">Plan lekcji niedostępny</string>
|
||||||
<string name="error_521_reason">Ograniczony dostęp do dziennika</string>
|
<string name="error_521_reason">Ograniczony dostęp do dziennika</string>
|
||||||
|
<string name="error_522_reason">Sesja wygasła</string>
|
||||||
<string name="error_530_reason">Nie można pobrać informacji o klasie i szkole</string>
|
<string name="error_530_reason">Nie można pobrać informacji o klasie i szkole</string>
|
||||||
|
|
||||||
<string name="error_801_reason">ERROR_TEMPLATE_WEB_OTHER</string>
|
<string name="error_801_reason">ERROR_TEMPLATE_WEB_OTHER</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user