forked from github/szkolny
[APIv2/Mobidziennik] Add Homework, Events, Timetable. Fix Users.
This commit is contained in:
parent
bbaa405c59
commit
2730c73413
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-6.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2
|
||||
|
||||
import java.util.regex.Pattern
|
||||
|
||||
object Regexes {
|
||||
val MOBIDZIENNIK_GRADES_SUBJECT_NAME by lazy {
|
||||
"<div.*?>\\n*\\s*(.+?)\\s*\\n*(?:<.*?)??</div>".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
val MOBIDZIENNIK_EVENT_TYPE by lazy {
|
||||
"\\(([0-9A-ząęóżźńśłć]*?)\\)$".toRegex(RegexOption.DOT_MATCHES_ALL)
|
||||
}
|
||||
}
|
@ -4,9 +4,6 @@
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web
|
||||
|
||||
import android.util.SparseArray
|
||||
import androidx.collection.SparseArrayCompat
|
||||
import androidx.core.util.forEach
|
||||
import pl.szczodrzynski.edziennik.api.v2.ERROR_MOBIDZIENNIK_WEB_INVALID_RESPONSE
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.MobidziennikWeb
|
||||
@ -42,9 +39,9 @@ class MobidziennikApi(override val data: DataMobidziennik,
|
||||
16 -> MobidziennikApiAttendance(data, rows)
|
||||
17 -> MobidziennikApiNotices(data, rows)
|
||||
18 -> MobidziennikApiGrades(data, rows)
|
||||
/*21 -> MobidziennikApiEvents(data, rows)
|
||||
21 -> MobidziennikApiEvents(data, rows)
|
||||
23 -> MobidziennikApiHomework(data, rows)
|
||||
24 -> MobidziennikApiTimetable(data, rows)*/
|
||||
24 -> MobidziennikApiTimetable(data, rows)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-8.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.core.util.contains
|
||||
import pl.szczodrzynski.edziennik.api.v2.Regexes
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
class MobidziennikApiEvents(val data: DataMobidziennik, rows: List<String>) {
|
||||
init {
|
||||
for (row in rows) {
|
||||
if (row.isEmpty())
|
||||
continue
|
||||
val cols = row.split("|")
|
||||
|
||||
val teamId = cols[2].toLong()
|
||||
if (data.teamList.contains(teamId)) {
|
||||
|
||||
val id = cols[0].toLong()
|
||||
val teacherId = cols[1].toLong()
|
||||
val subjectId = cols[3].toLong()
|
||||
var type = Event.TYPE_DEFAULT
|
||||
var topic = cols[5]
|
||||
Regexes.MOBIDZIENNIK_EVENT_TYPE.find(topic)?.let {
|
||||
val typeText = it.value
|
||||
when (typeText) {
|
||||
"sprawdzian" -> type = Event.TYPE_EXAM
|
||||
"kartkówka" -> type = Event.TYPE_SHORT_QUIZ
|
||||
}
|
||||
topic = topic.replace("($typeText)", "").trim()
|
||||
}
|
||||
val eventDate = Date.fromYmd(cols[4])
|
||||
val startTime = Time.fromYmdHm(cols[6])
|
||||
val format = SimpleDateFormat("yyyyMMddHHmmss", Locale.US)
|
||||
val addedDate = try {
|
||||
format.parse(cols[7]).time
|
||||
} catch (e: ParseException) {
|
||||
e.printStackTrace()
|
||||
System.currentTimeMillis()
|
||||
}
|
||||
|
||||
|
||||
val eventObject = Event(
|
||||
data.profileId,
|
||||
id,
|
||||
eventDate,
|
||||
startTime,
|
||||
topic,
|
||||
-1,
|
||||
type,
|
||||
false,
|
||||
teacherId,
|
||||
subjectId,
|
||||
teamId)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
data.profileId,
|
||||
Metadata.TYPE_EVENT,
|
||||
id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false,
|
||||
addedDate
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-8.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.core.util.contains
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||
|
||||
class MobidziennikApiHomework(val data: DataMobidziennik, rows: List<String>) {
|
||||
init {
|
||||
for (row in rows) {
|
||||
if (row.isEmpty())
|
||||
continue
|
||||
val cols = row.split("|")
|
||||
|
||||
val teamId = cols[5].toLong()
|
||||
if (data.teamList.contains(teamId)) {
|
||||
|
||||
val id = cols[0].toLong()
|
||||
val teacherId = cols[7].toLong()
|
||||
val subjectId = cols[6].toLong()
|
||||
val topic = cols[1]
|
||||
val eventDate = Date.fromYmd(cols[2])
|
||||
val startTime = Time.fromYmdHm(cols[3])
|
||||
|
||||
val eventObject = Event(
|
||||
data.profileId,
|
||||
id,
|
||||
eventDate,
|
||||
startTime,
|
||||
topic,
|
||||
-1,
|
||||
Event.TYPE_HOMEWORK,
|
||||
false,
|
||||
teacherId,
|
||||
subjectId,
|
||||
teamId)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
data.profileId,
|
||||
Metadata.TYPE_HOMEWORK,
|
||||
id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-8.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
||||
|
||||
import android.graphics.Color
|
||||
import androidx.core.util.contains
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.GradeCategory
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.Lesson
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.lessons.LessonChange
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.fixWhiteSpaces
|
||||
import pl.szczodrzynski.edziennik.singleOrNull
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.strToInt
|
||||
|
||||
class MobidziennikApiTimetable(val data: DataMobidziennik, rows: List<String>) {
|
||||
init {
|
||||
for (lessonStr in rows) {
|
||||
if (lessonStr.isNotEmpty()) {
|
||||
val lesson = lessonStr.split("|")
|
||||
|
||||
if (lesson[0].toInt() != data.studentId)
|
||||
continue
|
||||
|
||||
if (lesson[1] == "plan_lekcji" || lesson[1] == "lekcja") {
|
||||
val lessonObject = Lesson(data.profileId, lesson[2], lesson[3], lesson[4])
|
||||
|
||||
data.subjectList.singleOrNull { it.longName == lesson[5] }?.let {
|
||||
lessonObject.subjectId = it.id
|
||||
}
|
||||
data.teacherList.singleOrNull { it.fullNameLastFirst == (lesson[7]+" "+lesson[6]).fixWhiteSpaces() }?.let {
|
||||
lessonObject.teacherId = it.id
|
||||
}
|
||||
data.teamList.singleOrNull { it.name == lesson[8]+lesson[9] }?.let {
|
||||
lessonObject.teamId = it.id
|
||||
}
|
||||
lessonObject.classroomName = lesson[11]
|
||||
data.lessonList.add(lessonObject)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// searching for all changes
|
||||
for (lessonStr in rows) {
|
||||
if (lessonStr.isNotEmpty()) {
|
||||
val lesson = lessonStr.split("|")
|
||||
|
||||
if (lesson[0].toInt() != data.studentId)
|
||||
continue
|
||||
|
||||
if (lesson[1] == "zastepstwo" || lesson[1] == "lekcja_odwolana") {
|
||||
val lessonChange = LessonChange(data.profileId, lesson[2], lesson[3], lesson[4])
|
||||
|
||||
data.subjectList.singleOrNull { it.longName == lesson[5] }?.let {
|
||||
lessonChange.subjectId = it.id
|
||||
}
|
||||
data.teacherList.singleOrNull { it.fullNameLastFirst == (lesson[7]+" "+lesson[6]).fixWhiteSpaces() }?.let {
|
||||
lessonChange.teacherId = it.id
|
||||
}
|
||||
data.teamList.singleOrNull { it.name == lesson[8]+lesson[9] }?.let {
|
||||
lessonChange.teamId = it.id
|
||||
}
|
||||
|
||||
if (lesson[1] == "zastepstwo") {
|
||||
lessonChange.type = LessonChange.TYPE_CHANGE
|
||||
}
|
||||
else if (lesson[1] == "lekcja_odwolana") {
|
||||
lessonChange.type = LessonChange.TYPE_CANCELLED
|
||||
}
|
||||
else if (lesson[1] == "lekcja") {
|
||||
lessonChange.type = LessonChange.TYPE_ADDED
|
||||
}
|
||||
lessonChange.classroomName = lesson[11]
|
||||
|
||||
val originalLesson = lessonChange.getOriginalLesson(data.lessonList)
|
||||
|
||||
if (lessonChange.type == LessonChange.TYPE_ADDED) {
|
||||
if (originalLesson == null) {
|
||||
// original lesson doesn't exist, save a new addition
|
||||
// TODO
|
||||
/*if (!RegisterLessonChange.existsAddition(app.profile, registerLessonChange)) {
|
||||
app.profile.timetable.addLessonAddition(registerLessonChange);
|
||||
}*/
|
||||
} else {
|
||||
// original lesson exists, so we need to compare them
|
||||
if (!lessonChange.matches(originalLesson)) {
|
||||
// the lessons are different, so it's probably a lesson change
|
||||
// ahhh this damn API
|
||||
lessonChange.type = LessonChange.TYPE_CHANGE
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (lessonChange.type != LessonChange.TYPE_ADDED) {
|
||||
// it's not a lesson addition
|
||||
data.lessonChangeList.add(lessonChange)
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
data.profileId,
|
||||
Metadata.TYPE_LESSON_CHANGE,
|
||||
lessonChange.id,
|
||||
data.profile?.empty ?: false,
|
||||
data.profile?.empty ?: false,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
if (originalLesson == null) {
|
||||
// there is no original lesson, so we have to add one in order to change it
|
||||
data.lessonList.add(Lesson.fromLessonChange(lessonChange))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ package pl.szczodrzynski.edziennik.api.v2.mobidziennik.data.web.apidata
|
||||
|
||||
import pl.szczodrzynski.edziennik.api.v2.mobidziennik.DataMobidziennik
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher
|
||||
import pl.szczodrzynski.edziennik.fixWhiteSpaces
|
||||
|
||||
class MobidziennikApiUsers(val data: DataMobidziennik, rows: List<String>) {
|
||||
init {
|
||||
@ -15,8 +16,8 @@ class MobidziennikApiUsers(val data: DataMobidziennik, rows: List<String>) {
|
||||
val cols = row.split("|")
|
||||
|
||||
val id = cols[0].toLong()
|
||||
val name = cols[4].trim()
|
||||
val surname = cols[5].trim()
|
||||
val name = cols[4].fixWhiteSpaces()
|
||||
val surname = cols[5].fixWhiteSpaces()
|
||||
|
||||
data.teachersMap.put(id, "$surname $name")
|
||||
data.teacherList.put(id, Teacher(data.profileId, id, name, surname))
|
||||
|
Loading…
Reference in New Issue
Block a user