forked from github/szkolny
[API/Edudziennik] Add getting homework.
This commit is contained in:
parent
cc3e6d97dd
commit
4a38906194
@ -132,6 +132,9 @@ object Regexes {
|
|||||||
val EDUDZIENNIK_ANNOUNCEMENT_ID by lazy {
|
val EDUDZIENNIK_ANNOUNCEMENT_ID by lazy {
|
||||||
"""/Announcement/([\w-_]+?)/""".toRegex()
|
"""/Announcement/([\w-_]+?)/""".toRegex()
|
||||||
}
|
}
|
||||||
|
val EDUDZIENNIK_HOMEWORK_ID by lazy {
|
||||||
|
"""/Homework/([\w-_]+?)/""".toRegex()
|
||||||
|
}
|
||||||
|
|
||||||
val EDUDZIENNIK_SCHOOL_DETAIL_ID by lazy {
|
val EDUDZIENNIK_SCHOOL_DETAIL_ID by lazy {
|
||||||
"""<a id="School_detail".*?/School/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)
|
"""<a id="School_detail".*?/School/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
@ -104,6 +104,9 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
|||||||
val studentAndTeacherClassEndpoint: String
|
val studentAndTeacherClassEndpoint: String
|
||||||
get() = "Students/$studentId/Teachers/$classId/"
|
get() = "Students/$studentId/Teachers/$classId/"
|
||||||
|
|
||||||
|
val courseStudentEndpoint: String
|
||||||
|
get() = "Course/$studentId/"
|
||||||
|
|
||||||
fun getSubject(longId: String, name: String): Subject {
|
fun getSubject(longId: String, name: String): Subject {
|
||||||
val id = longId.crc32()
|
val id = longId.crc32()
|
||||||
return subjectList.singleOrNull { it.id == id } ?: run {
|
return subjectList.singleOrNull { it.id == id } ?: run {
|
||||||
|
@ -14,6 +14,7 @@ const val ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE = 1012
|
|||||||
const val ENDPOINT_EDUDZIENNIK_WEB_EXAMS = 1013
|
const val ENDPOINT_EDUDZIENNIK_WEB_EXAMS = 1013
|
||||||
const val ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE = 1014
|
const val ENDPOINT_EDUDZIENNIK_WEB_ATTENDANCE = 1014
|
||||||
const val ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS = 1015
|
const val ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS = 1015
|
||||||
|
const val ENDPOINT_EDUDZIENNIK_WEB_HOMEWORK = 1016
|
||||||
const val ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER = 1030
|
const val ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER = 1030
|
||||||
|
|
||||||
val EdudziennikFeatures = listOf(
|
val EdudziennikFeatures = listOf(
|
||||||
@ -39,7 +40,13 @@ val EdudziennikFeatures = listOf(
|
|||||||
|
|
||||||
/* Agenda */
|
/* Agenda */
|
||||||
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_AGENDA, listOf(
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_AGENDA, listOf(
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_EXAMS to LOGIN_METHOD_EDUDZIENNIK_WEB
|
ENDPOINT_EDUDZIENNIK_WEB_EXAMS to LOGIN_METHOD_EDUDZIENNIK_WEB,
|
||||||
|
ENDPOINT_EDUDZIENNIK_WEB_HOMEWORK to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
|
/* Homework */
|
||||||
|
Feature(LOGIN_TYPE_EDUDZIENNIK, FEATURE_HOMEWORK, listOf(
|
||||||
|
ENDPOINT_EDUDZIENNIK_WEB_HOMEWORK to LOGIN_METHOD_EDUDZIENNIK_WEB
|
||||||
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
), listOf(LOGIN_METHOD_EDUDZIENNIK_WEB)),
|
||||||
|
|
||||||
/* Attendance */
|
/* Attendance */
|
||||||
|
@ -64,6 +64,10 @@ class EdudziennikData(val data: DataEdudziennik, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_announcements)
|
data.startProgress(R.string.edziennik_progress_endpoint_announcements)
|
||||||
EdudziennikWebAnnouncements(data, onSuccess)
|
EdudziennikWebAnnouncements(data, onSuccess)
|
||||||
}
|
}
|
||||||
|
ENDPOINT_EDUDZIENNIK_WEB_HOMEWORK -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||||
|
EdudziennikWebHomework(data, onSuccess)
|
||||||
|
}
|
||||||
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER -> {
|
ENDPOINT_EDUDZIENNIK_WEB_LUCKY_NUMBER -> {
|
||||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||||
EdudziennikWebLuckyNumber(data, onSuccess)
|
EdudziennikWebLuckyNumber(data, onSuccess)
|
||||||
|
@ -27,43 +27,45 @@ class EdudziennikWebAnnouncements(override val data: DataEdudziennik,
|
|||||||
webGet(TAG, data.schoolClassEndpoint + "Announcements") { text ->
|
webGet(TAG, data.schoolClassEndpoint + "Announcements") { text ->
|
||||||
val doc = Jsoup.parse(text)
|
val doc = Jsoup.parse(text)
|
||||||
|
|
||||||
doc.select("table.list tbody tr").forEach { announcementElement ->
|
if (doc.getElementsByClass("message").text().trim() != "Brak ogłoszeń.") {
|
||||||
val titleElement = announcementElement.child(0).child(0)
|
doc.select("table.list tbody tr").forEach { announcementElement ->
|
||||||
|
val titleElement = announcementElement.child(0).child(0)
|
||||||
|
|
||||||
val longId = EDUDZIENNIK_ANNOUNCEMENT_ID.find(titleElement.attr("href"))?.get(1)
|
val longId = EDUDZIENNIK_ANNOUNCEMENT_ID.find(titleElement.attr("href"))?.get(1)
|
||||||
?: return@forEach
|
?: return@forEach
|
||||||
val id = longId.crc32()
|
val id = longId.crc32()
|
||||||
val subject = titleElement.text()
|
val subject = titleElement.text()
|
||||||
|
|
||||||
val teacherName = announcementElement.child(1).text()
|
val teacherName = announcementElement.child(1).text()
|
||||||
val teacher = teacherName.splitName()?.let { (teacherFirstName, teacherLastName) ->
|
val teacher = teacherName.splitName()?.let { (teacherFirstName, teacherLastName) ->
|
||||||
data.getTeacher(teacherFirstName, teacherLastName)
|
data.getTeacher(teacherFirstName, teacherLastName)
|
||||||
} ?: return@forEach
|
} ?: return@forEach
|
||||||
|
|
||||||
val dateString = announcementElement.getElementsByClass("datetime").first().text()
|
val dateString = announcementElement.getElementsByClass("datetime").first().text()
|
||||||
val startDate = Date.fromY_m_d(dateString)
|
val startDate = Date.fromY_m_d(dateString)
|
||||||
val addedDate = Date.fromIsoHm(dateString)
|
val addedDate = Date.fromIsoHm(dateString)
|
||||||
|
|
||||||
val announcementObject = Announcement(
|
val announcementObject = Announcement(
|
||||||
profileId,
|
profileId,
|
||||||
id,
|
id,
|
||||||
subject,
|
subject,
|
||||||
null,
|
null,
|
||||||
startDate,
|
startDate,
|
||||||
null,
|
null,
|
||||||
teacher.id,
|
teacher.id,
|
||||||
longId
|
longId
|
||||||
)
|
)
|
||||||
|
|
||||||
data.announcementIgnoreList.add(announcementObject)
|
data.announcementIgnoreList.add(announcementObject)
|
||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
profileId,
|
profileId,
|
||||||
Metadata.TYPE_ANNOUNCEMENT,
|
Metadata.TYPE_ANNOUNCEMENT,
|
||||||
id,
|
id,
|
||||||
profile.empty,
|
profile.empty,
|
||||||
profile.empty,
|
profile.empty,
|
||||||
addedDate
|
addedDate
|
||||||
))
|
))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_ANNOUNCEMENTS, SYNC_ALWAYS)
|
||||||
|
@ -45,7 +45,7 @@ class EdudziennikWebExams(override val data: DataEdudziennik,
|
|||||||
val date = Date.fromY_m_d(dateString)
|
val date = Date.fromY_m_d(dateString)
|
||||||
|
|
||||||
val lessons = data.app.db.timetableDao().getForDateNow(profileId, date)
|
val lessons = data.app.db.timetableDao().getForDateNow(profileId, date)
|
||||||
val startTime = lessons.firstOrNull { it.subjectId == subject.id }?.startTime
|
val startTime = lessons.firstOrNull { it.subjectId == subject.id }?.displayStartTime
|
||||||
|
|
||||||
val eventTypeElement = examElement.child(3).child(0)
|
val eventTypeElement = examElement.child(3).child(0)
|
||||||
val eventTypeId = EDUDZIENNIK_EVENT_TYPE_ID.find(eventTypeElement.attr("href"))?.get(1)
|
val eventTypeId = EDUDZIENNIK_EVENT_TYPE_ID.find(eventTypeElement.attr("href"))?.get(1)
|
||||||
@ -78,7 +78,7 @@ class EdudziennikWebExams(override val data: DataEdudziennik,
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_DEFAULT))
|
data.toRemove.add(DataRemoveModel.Events.futureExceptType(Event.TYPE_HOMEWORK))
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_EXAMS, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_EXAMS, SYNC_ALWAYS)
|
||||||
onSuccess()
|
onSuccess()
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-12-29
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
||||||
|
|
||||||
|
import org.jsoup.Jsoup
|
||||||
|
import pl.szczodrzynski.edziennik.crc32
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_HOMEWORK_ID
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_SUBJECT_ID
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_HOMEWORK
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.models.DataRemoveModel
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
|
import pl.szczodrzynski.edziennik.get
|
||||||
|
import pl.szczodrzynski.edziennik.splitName
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class EdudziennikWebHomework(override val data: DataEdudziennik,
|
||||||
|
val onSuccess: () -> Unit) : EdudziennikWeb(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "EdudziennikWebHomework"
|
||||||
|
}
|
||||||
|
|
||||||
|
init { data.profile?.also { profile ->
|
||||||
|
webGet(TAG, data.courseStudentEndpoint + "Homework", xhr = true) { text ->
|
||||||
|
val doc = Jsoup.parseBodyFragment("<table>" + text.trim() + "</table>")
|
||||||
|
|
||||||
|
if (doc.getElementsByClass("message").text().trim() != "Brak prac domowych") {
|
||||||
|
doc.select("tr").forEach { homeworkElement ->
|
||||||
|
val dateElement = homeworkElement.getElementsByClass("date").first().child(0)
|
||||||
|
val id = EDUDZIENNIK_HOMEWORK_ID.find(dateElement.attr("href"))?.get(1)?.crc32()
|
||||||
|
?: return@forEach
|
||||||
|
val date = Date.fromY_m_d(dateElement.text())
|
||||||
|
|
||||||
|
val subjectElement = homeworkElement.child(1).child(0)
|
||||||
|
val subjectId = EDUDZIENNIK_SUBJECT_ID.find(subjectElement.attr("href"))?.get(1)
|
||||||
|
?: return@forEach
|
||||||
|
val subjectName = subjectElement.text()
|
||||||
|
val subject = data.getSubject(subjectId, subjectName)
|
||||||
|
|
||||||
|
val lessons = data.app.db.timetableDao().getForDateNow(profileId, date)
|
||||||
|
val startTime = lessons.firstOrNull { it.subjectId == subject.id }?.displayStartTime
|
||||||
|
|
||||||
|
val teacherName = homeworkElement.child(2).text()
|
||||||
|
val teacher = teacherName.splitName()?.let { (teacherFirstName, teacherLastName) ->
|
||||||
|
data.getTeacher(teacherFirstName, teacherLastName)
|
||||||
|
} ?: return@forEach
|
||||||
|
|
||||||
|
val topic = homeworkElement.child(4).text()
|
||||||
|
|
||||||
|
val eventObject = Event(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
date,
|
||||||
|
startTime,
|
||||||
|
topic,
|
||||||
|
-1,
|
||||||
|
Event.TYPE_HOMEWORK,
|
||||||
|
false,
|
||||||
|
teacher.id,
|
||||||
|
subject.id,
|
||||||
|
data.teamClass?.id ?: -1
|
||||||
|
)
|
||||||
|
|
||||||
|
data.eventList.add(eventObject)
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_HOMEWORK,
|
||||||
|
id,
|
||||||
|
profile.empty,
|
||||||
|
profile.empty,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data.toRemove.add(DataRemoveModel.Events.futureWithType(Event.TYPE_HOMEWORK))
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_EDUDZIENNIK_WEB_HOMEWORK, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
} ?: onSuccess() }
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user