From 3cdca5eb3397a473bf331c789e9fdd752eae84b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 2 Oct 2021 16:15:02 +0200 Subject: [PATCH 1/2] [API/Mobidziennik] Fix showing homework attachments. --- .../edziennik/data/api/Regexes.kt | 23 +++++--- .../data/web/EdudziennikWebGetHomework.kt | 1 + .../synergia/LibrusSynergiaGetHomework.kt | 1 + .../data/synergia/LibrusSynergiaHomework.kt | 1 + .../data/web/MobidziennikWebGetEvent.kt | 2 +- .../data/web/MobidziennikWebGetHomework.kt | 59 ++++++++++++------- .../data/web/MobidziennikWebGetMessage.kt | 20 +++---- .../data/web/MobidziennikWebHomework.kt | 7 ++- .../podlasie/data/api/PodlasieApiEvents.kt | 1 + .../podlasie/data/api/PodlasieApiHomework.kt | 1 + .../data/api/edziennik/vulcan/Vulcan.kt | 1 + 11 files changed, 72 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt index 597c02d7..b42de2c4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt @@ -54,15 +54,16 @@ object Regexes { """events: (.+),$""".toRegex(RegexOption.MULTILINE) } + val MOBIDZIENNIK_WEB_ATTACHMENT by lazy { + """href="https://.+?\.mobidziennik.pl/.+?&(?:amp;)?zalacznik(_rozwiazania)?=([0-9]+)".+?>(.+?)(?: )?""".toRegex() + } + val MOBIDZIENNIK_MESSAGE_READ_DATE by lazy { """czas przeczytania:.+?,\s([0-9]+)\s(.+?)\s([0-9]{4}),\sgodzina\s([0-9:]+)""".toRegex(DOT_MATCHES_ALL) } val MOBIDZIENNIK_MESSAGE_SENT_READ_DATE by lazy { """.+?,\s([0-9]+)\s(.+?)\s([0-9]{4}),\sgodzina\s([0-9:]+)""".toRegex(DOT_MATCHES_ALL) } - val MOBIDZIENNIK_MESSAGE_ATTACHMENT by lazy { - """href="https://.+?\.mobidziennik.pl/.+?&(?:amp;)?zalacznik=([0-9]+)"(?:.+?(.+?)\s*\s*\((.+?),\s*(.+?)\)""".toRegex(DOT_MATCHES_ALL) } - val MOBIDZIENNIK_HOMEWORK_ROW by lazy { + val MOBIDZIENNIK_MOBILE_HOMEWORK_ROW by lazy { """class="rowRolling">(.+?\s*)""".toRegex(DOT_MATCHES_ALL) } - val MOBIDZIENNIK_HOMEWORK_ITEM by lazy { + val MOBIDZIENNIK_MOBILE_HOMEWORK_ITEM by lazy { """

(.+?):\s*(.+?)\s*

""".toRegex(DOT_MATCHES_ALL) } - val MOBIDZIENNIK_HOMEWORK_BODY by lazy { + val MOBIDZIENNIK_MOBILE_HOMEWORK_BODY by lazy { """Treść:(.+?)

""".toRegex(DOT_MATCHES_ALL) } - val MOBIDZIENNIK_HOMEWORK_ID by lazy { - """zadanieFormularz\(([0-9]+),""".toRegex(DOT_MATCHES_ALL) + val MOBIDZIENNIK_MOBILE_HOMEWORK_ID by lazy { + """name="id_zadania" value="([0-9]+)"""".toRegex(DOT_MATCHES_ALL) } - val MOBIDZIENNIK_HOMEWORK_ATTACHMENT by lazy { + val MOBIDZIENNIK_MOBILE_HOMEWORK_ATTACHMENT by lazy { """zalacznik(_zadania)?=([0-9]+)'.+?word-break">(.+?)""".toRegex(DOT_MATCHES_ALL) } + val MOBIDZIENNIK_WEB_HOMEWORK_ADDED_DATE by lazy { + """Wpisał\(a\):\s+\s+(.+?), (.+?), ([0-9]{1,2}) (.+?) ([0-9]{4}), godzina ([0-9:]+)""".toRegex() + } + val MOBIDZIENNIK_TIMETABLE_TOP by lazy { """

.+?
""".toRegex(DOT_MATCHES_ALL) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebGetHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebGetHomework.kt index 84171699..5213b7eb 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebGetHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebGetHomework.kt @@ -29,6 +29,7 @@ class EdudziennikWebGetHomework( if (description != null) event.topic = Html.fromHtml(description).toString() event.homeworkBody = "" + event.isDownloaded = true event.attachmentNames = null data.eventList += event diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt index 379bd42d..75903907 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaGetHomework.kt @@ -24,6 +24,7 @@ class LibrusSynergiaGetHomework(override val data: DataLibrus, event.topic = table[1].select("td")[1].text() event.homeworkBody = Html.fromHtml(table[5].select("td")[1].html()).toString() + event.isDownloaded = true event.attachmentIds = mutableListOf() event.attachmentNames = mutableListOf() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaHomework.kt index d33f6911..42064610 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/librus/data/synergia/LibrusSynergiaHomework.kt @@ -79,6 +79,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus, teamId = data.teamClass?.id ?: -1, addedDate = addedDate.inMillis ) + eventObject.isDownloaded = false data.eventList.add(eventObject) data.metadataList.add(Metadata( diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetEvent.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetEvent.kt index 27cacb5d..41e46e65 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetEvent.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetEvent.kt @@ -42,9 +42,9 @@ class MobidziennikWebGetEvent( event.topic = topic event.homeworkBody = body + event.isDownloaded = true event.teacherId = teacher.id event.addedDate = addedDate.inMillis - event.isDownloaded = true } data.eventList.add(event) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt index b0699b4b..5b8d348f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetHomework.kt @@ -12,41 +12,58 @@ import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent import pl.szczodrzynski.edziennik.data.db.full.EventFull import pl.szczodrzynski.edziennik.get import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.utils.models.Time class MobidziennikWebGetHomework(override val data: DataMobidziennik, val event: EventFull, val onSuccess: () -> Unit ) : MobidziennikWeb(data, null) { companion object { - private const val TAG = "MobidziennikWebHomework" + private const val TAG = "MobidziennikWebGetHomework" } init { - val endpoint = if (event.date >= Date.getToday()) - "zadaniadomowe" - else - "zadaniadomowearchiwalne" - - webGet(TAG, "/mobile/$endpoint") { text -> + webGet(TAG, "/dziennik/wyslijzadanie/?id_zadania=${event.id}&uczen=${data.studentId}") { text -> MobidziennikLuckyNumberExtractor(data, text) - Regexes.MOBIDZIENNIK_HOMEWORK_ROW.findAll(text).forEach { homeworkMatch -> - val tableRow = homeworkMatch[1].ifBlank { return@forEach } - - val id = Regexes.MOBIDZIENNIK_HOMEWORK_ID.find(tableRow)?.get(1)?.toLongOrNull() ?: return@forEach - if (event.id != id) + event.clearAttachments() + Regexes.MOBIDZIENNIK_WEB_ATTACHMENT.findAll(text).forEach { match -> + if (match[1].isNotEmpty()) return@forEach - - event.attachmentIds = mutableListOf() - event.attachmentNames = mutableListOf() - Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach { - event.attachmentIds?.add(it[2].toLongOrNull() ?: return@forEach) - event.attachmentNames?.add(it[3]) - } - - event.homeworkBody = "" + val attachmentId = match[2].toLong() + val attachmentName = match[3] + event.addAttachment(attachmentId, attachmentName) } + Regexes.MOBIDZIENNIK_WEB_HOMEWORK_ADDED_DATE.find(text)?.let { + // (Kowalski Jan), (wtorek), (2) (stycznia) (2019), godzina (12:34:56) + val month = when (it[4]) { + "stycznia" -> 1 + "lutego" -> 2 + "marca" -> 3 + "kwietnia" -> 4 + "maja" -> 5 + "czerwca" -> 6 + "lipca" -> 7 + "sierpnia" -> 8 + "września" -> 9 + "października" -> 10 + "listopada" -> 11 + "grudnia" -> 12 + else -> 1 + } + val addedDate = Date( + it[5].toInt(), + month, + it[3].toInt() + ) + val time = Time.fromH_m_s(it[6]) + event.addedDate = addedDate.combineWith(time) + } + + event.homeworkBody = "" + event.isDownloaded = true + data.eventList.add(event) data.eventListReplace = true diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetMessage.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetMessage.kt index 7282cc2d..542e4488 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetMessage.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebGetMessage.kt @@ -118,18 +118,16 @@ class MobidziennikWebGetMessage(override val data: DataMobidziennik, this.body = body.html() clearAttachments() - content.select("ul li").map { it.select("a").first() }.forEach { - val attachmentName = it.ownText() - Regexes.MOBIDZIENNIK_MESSAGE_ATTACHMENT.find(it.outerHtml())?.let { match -> - val attachmentId = match[1].toLong() - var size = match[2].toFloatOrNull() ?: -1f - when (match[3]) { - "K" -> size *= 1024f - "M" -> size *= 1024f * 1024f - "G" -> size *= 1024f * 1024f * 1024f - } - message.addAttachment(attachmentId, attachmentName, size.toLong()) + Regexes.MOBIDZIENNIK_WEB_ATTACHMENT.findAll(text).forEach { match -> + val attachmentId = match[2].toLong() + val attachmentName = match[3] + var size = match[4].toFloatOrNull() ?: -1f + when (match[5]) { + "K" -> size *= 1024f + "M" -> size *= 1024f * 1024f + "G" -> size *= 1024f * 1024f * 1024f } + message.addAttachment(attachmentId, attachmentName, size.toLong()) } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebHomework.kt index 944b21ea..ddae85e6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/mobidziennik/data/web/MobidziennikWebHomework.kt @@ -33,14 +33,14 @@ class MobidziennikWebHomework(override val data: DataMobidziennik, webGet(TAG, "/mobile/$endpoint") { text -> MobidziennikLuckyNumberExtractor(data, text) - Regexes.MOBIDZIENNIK_HOMEWORK_ROW.findAll(text).forEach { homeworkMatch -> + Regexes.MOBIDZIENNIK_MOBILE_HOMEWORK_ROW.findAll(text).forEach { homeworkMatch -> val tableRow = homeworkMatch[1].ifBlank { return@forEach } /*val items = Regexes.MOBIDZIENNIK_HOMEWORK_ITEM.findAll(tableRow).map { match -> match[1] to match[2].fixWhiteSpaces() }.toList()*/ - val id = Regexes.MOBIDZIENNIK_HOMEWORK_ID.find(tableRow)?.get(1)?.toLongOrNull() ?: return@forEach + val id = Regexes.MOBIDZIENNIK_MOBILE_HOMEWORK_ID.find(tableRow)?.get(1)?.toLongOrNull() ?: return@forEach if (event.id != id) return@forEach @@ -48,12 +48,13 @@ class MobidziennikWebHomework(override val data: DataMobidziennik, event.attachmentIds = mutableListOf() event.attachmentNames = mutableListOf() - Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach { + Regexes.MOBIDZIENNIK_MOBILE_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach { event.attachmentIds?.add(it[1].toLongOrNull() ?: return@forEach) event.attachmentNames?.add(it[2]) } event.homeworkBody = "" + event.isDownloaded = true } //data.eventList.add(eventObject) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt index 8a169ee7..6139b402 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiEvents.kt @@ -57,6 +57,7 @@ class PodlasieApiEvents(val data: DataPodlasie, val rows: List) { addedDate = addedDate ).apply { homeworkBody = description + isDownloaded = true } data.eventList.add(eventObject) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiHomework.kt index 6ab53328..1165cf79 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/podlasie/data/api/PodlasieApiHomework.kt @@ -37,6 +37,7 @@ class PodlasieApiHomework(val data: DataPodlasie, val rows: List) { addedDate = addedDate ).apply { homeworkBody = description + isDownloaded = true } eventObject.attachmentIds = mutableListOf() diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt index d066aca0..64c87bf6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt @@ -164,6 +164,7 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va override fun getEvent(eventFull: EventFull) { eventFull.homeworkBody = "" + eventFull.isDownloaded = true EventBus.getDefault().postSticky(EventGetEvent(eventFull)) completed() From 2d277e80cc23df5cbaef98a167dc1c5e2eec7c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Sat, 2 Oct 2021 16:15:32 +0200 Subject: [PATCH 2/2] [UI] Restore showing message attachment size. --- .../edziennik/ui/modules/messages/MessageFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt index e147dea6..3f0cd068 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/messages/MessageFragment.kt @@ -301,8 +301,8 @@ class MessageFragment : Fragment(), CoroutineScope { it.putInt("profileId", message.profileId) it.putLongArray("attachmentIds", message.attachmentIds!!.toLongArray()) it.putStringArray("attachmentNames", message.attachmentNames!!.toTypedArray()) - //if (message.attachmentSizes.isNotNullNorEmpty()) - // it.putLongArray("attachmentSizes", message.attachmentSizes!!.toLongArray()) + if (message.attachmentSizes.isNotNullNorEmpty()) + it.putLongArray("attachmentSizes", message.attachmentSizes!!.toLongArray()) }, owner = message) } }