mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[API/Mobidziennik] Fix showing homework attachments.
This commit is contained in:
parent
591abb4bb8
commit
3cdca5eb33
@ -54,15 +54,16 @@ object Regexes {
|
|||||||
"""events: (.+),$""".toRegex(RegexOption.MULTILINE)
|
"""events: (.+),$""".toRegex(RegexOption.MULTILINE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val MOBIDZIENNIK_WEB_ATTACHMENT by lazy {
|
||||||
|
"""href="https://.+?\.mobidziennik.pl/.+?&(?:amp;)?zalacznik(_rozwiazania)?=([0-9]+)".+?>(.+?)(?: <small.+?\(([0-9.]+)\s(M|K|G|)B\)</small>)?</a>""".toRegex()
|
||||||
|
}
|
||||||
|
|
||||||
val MOBIDZIENNIK_MESSAGE_READ_DATE by lazy {
|
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)
|
"""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 {
|
val MOBIDZIENNIK_MESSAGE_SENT_READ_DATE by lazy {
|
||||||
""".+?,\s([0-9]+)\s(.+?)\s([0-9]{4}),\sgodzina\s([0-9:]+)""".toRegex(DOT_MATCHES_ALL)
|
""".+?,\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]+)"(?:.+?<small.+?\(([0-9.]+)\s(M|K|G|)B\))*""".toRegex(DOT_MATCHES_ALL)
|
|
||||||
}
|
|
||||||
val MOBIDZIENNIK_MESSAGE_SENT_READ_BY by lazy {
|
val MOBIDZIENNIK_MESSAGE_SENT_READ_BY by lazy {
|
||||||
"""([0-9]+)/([0-9]+)""".toRegex()
|
"""([0-9]+)/([0-9]+)""".toRegex()
|
||||||
}
|
}
|
||||||
@ -104,22 +105,26 @@ object Regexes {
|
|||||||
"""<strong>(.+?)</strong>\s*<small>\s*\((.+?),\s*(.+?)\)""".toRegex(DOT_MATCHES_ALL)
|
"""<strong>(.+?)</strong>\s*<small>\s*\((.+?),\s*(.+?)\)""".toRegex(DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
|
|
||||||
val MOBIDZIENNIK_HOMEWORK_ROW by lazy {
|
val MOBIDZIENNIK_MOBILE_HOMEWORK_ROW by lazy {
|
||||||
"""class="rowRolling">(.+?</div>\s*</td>)""".toRegex(DOT_MATCHES_ALL)
|
"""class="rowRolling">(.+?</div>\s*</td>)""".toRegex(DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
val MOBIDZIENNIK_HOMEWORK_ITEM by lazy {
|
val MOBIDZIENNIK_MOBILE_HOMEWORK_ITEM by lazy {
|
||||||
"""<p><b>(.+?):</b>\s*(.+?)\s*</p>""".toRegex(DOT_MATCHES_ALL)
|
"""<p><b>(.+?):</b>\s*(.+?)\s*</p>""".toRegex(DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
val MOBIDZIENNIK_HOMEWORK_BODY by lazy {
|
val MOBIDZIENNIK_MOBILE_HOMEWORK_BODY by lazy {
|
||||||
"""Treść:</b>(.+?)<p><b>""".toRegex(DOT_MATCHES_ALL)
|
"""Treść:</b>(.+?)<p><b>""".toRegex(DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
val MOBIDZIENNIK_HOMEWORK_ID by lazy {
|
val MOBIDZIENNIK_MOBILE_HOMEWORK_ID by lazy {
|
||||||
"""zadanieFormularz\(([0-9]+),""".toRegex(DOT_MATCHES_ALL)
|
"""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">(.+?)</td>""".toRegex(DOT_MATCHES_ALL)
|
"""zalacznik(_zadania)?=([0-9]+)'.+?word-break">(.+?)</td>""".toRegex(DOT_MATCHES_ALL)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val MOBIDZIENNIK_WEB_HOMEWORK_ADDED_DATE by lazy {
|
||||||
|
"""Wpisał\(a\):</td>\s+<th>\s+(.+?), (.+?), ([0-9]{1,2}) (.+?) ([0-9]{4}), godzina ([0-9:]+)""".toRegex()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
val MOBIDZIENNIK_TIMETABLE_TOP by lazy {
|
val MOBIDZIENNIK_TIMETABLE_TOP by lazy {
|
||||||
"""<div class="plansc_top">.+?</div></div>""".toRegex(DOT_MATCHES_ALL)
|
"""<div class="plansc_top">.+?</div></div>""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
@ -29,6 +29,7 @@ class EdudziennikWebGetHomework(
|
|||||||
if (description != null) event.topic = Html.fromHtml(description).toString()
|
if (description != null) event.topic = Html.fromHtml(description).toString()
|
||||||
|
|
||||||
event.homeworkBody = ""
|
event.homeworkBody = ""
|
||||||
|
event.isDownloaded = true
|
||||||
event.attachmentNames = null
|
event.attachmentNames = null
|
||||||
|
|
||||||
data.eventList += event
|
data.eventList += event
|
||||||
|
@ -24,6 +24,7 @@ class LibrusSynergiaGetHomework(override val data: DataLibrus,
|
|||||||
|
|
||||||
event.topic = table[1].select("td")[1].text()
|
event.topic = table[1].select("td")[1].text()
|
||||||
event.homeworkBody = Html.fromHtml(table[5].select("td")[1].html()).toString()
|
event.homeworkBody = Html.fromHtml(table[5].select("td")[1].html()).toString()
|
||||||
|
event.isDownloaded = true
|
||||||
|
|
||||||
event.attachmentIds = mutableListOf()
|
event.attachmentIds = mutableListOf()
|
||||||
event.attachmentNames = mutableListOf()
|
event.attachmentNames = mutableListOf()
|
||||||
|
@ -79,6 +79,7 @@ class LibrusSynergiaHomework(override val data: DataLibrus,
|
|||||||
teamId = data.teamClass?.id ?: -1,
|
teamId = data.teamClass?.id ?: -1,
|
||||||
addedDate = addedDate.inMillis
|
addedDate = addedDate.inMillis
|
||||||
)
|
)
|
||||||
|
eventObject.isDownloaded = false
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
|
@ -42,9 +42,9 @@ class MobidziennikWebGetEvent(
|
|||||||
|
|
||||||
event.topic = topic
|
event.topic = topic
|
||||||
event.homeworkBody = body
|
event.homeworkBody = body
|
||||||
|
event.isDownloaded = true
|
||||||
event.teacherId = teacher.id
|
event.teacherId = teacher.id
|
||||||
event.addedDate = addedDate.inMillis
|
event.addedDate = addedDate.inMillis
|
||||||
event.isDownloaded = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data.eventList.add(event)
|
data.eventList.add(event)
|
||||||
|
@ -12,41 +12,58 @@ import pl.szczodrzynski.edziennik.data.api.events.EventGetEvent
|
|||||||
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
import pl.szczodrzynski.edziennik.data.db.full.EventFull
|
||||||
import pl.szczodrzynski.edziennik.get
|
import pl.szczodrzynski.edziennik.get
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
|
|
||||||
class MobidziennikWebGetHomework(override val data: DataMobidziennik,
|
class MobidziennikWebGetHomework(override val data: DataMobidziennik,
|
||||||
val event: EventFull,
|
val event: EventFull,
|
||||||
val onSuccess: () -> Unit
|
val onSuccess: () -> Unit
|
||||||
) : MobidziennikWeb(data, null) {
|
) : MobidziennikWeb(data, null) {
|
||||||
companion object {
|
companion object {
|
||||||
private const val TAG = "MobidziennikWebHomework"
|
private const val TAG = "MobidziennikWebGetHomework"
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val endpoint = if (event.date >= Date.getToday())
|
webGet(TAG, "/dziennik/wyslijzadanie/?id_zadania=${event.id}&uczen=${data.studentId}") { text ->
|
||||||
"zadaniadomowe"
|
|
||||||
else
|
|
||||||
"zadaniadomowearchiwalne"
|
|
||||||
|
|
||||||
webGet(TAG, "/mobile/$endpoint") { text ->
|
|
||||||
MobidziennikLuckyNumberExtractor(data, text)
|
MobidziennikLuckyNumberExtractor(data, text)
|
||||||
|
|
||||||
Regexes.MOBIDZIENNIK_HOMEWORK_ROW.findAll(text).forEach { homeworkMatch ->
|
event.clearAttachments()
|
||||||
val tableRow = homeworkMatch[1].ifBlank { return@forEach }
|
Regexes.MOBIDZIENNIK_WEB_ATTACHMENT.findAll(text).forEach { match ->
|
||||||
|
if (match[1].isNotEmpty())
|
||||||
val id = Regexes.MOBIDZIENNIK_HOMEWORK_ID.find(tableRow)?.get(1)?.toLongOrNull() ?: return@forEach
|
|
||||||
if (event.id != id)
|
|
||||||
return@forEach
|
return@forEach
|
||||||
|
val attachmentId = match[2].toLong()
|
||||||
event.attachmentIds = mutableListOf()
|
val attachmentName = match[3]
|
||||||
event.attachmentNames = mutableListOf()
|
event.addAttachment(attachmentId, attachmentName)
|
||||||
Regexes.MOBIDZIENNIK_HOMEWORK_ATTACHMENT.findAll(tableRow).forEach {
|
|
||||||
event.attachmentIds?.add(it[2].toLongOrNull() ?: return@forEach)
|
|
||||||
event.attachmentNames?.add(it[3])
|
|
||||||
}
|
|
||||||
|
|
||||||
event.homeworkBody = ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.eventList.add(event)
|
||||||
data.eventListReplace = true
|
data.eventListReplace = true
|
||||||
|
|
||||||
|
@ -118,18 +118,16 @@ class MobidziennikWebGetMessage(override val data: DataMobidziennik,
|
|||||||
this.body = body.html()
|
this.body = body.html()
|
||||||
|
|
||||||
clearAttachments()
|
clearAttachments()
|
||||||
content.select("ul li").map { it.select("a").first() }.forEach {
|
Regexes.MOBIDZIENNIK_WEB_ATTACHMENT.findAll(text).forEach { match ->
|
||||||
val attachmentName = it.ownText()
|
val attachmentId = match[2].toLong()
|
||||||
Regexes.MOBIDZIENNIK_MESSAGE_ATTACHMENT.find(it.outerHtml())?.let { match ->
|
val attachmentName = match[3]
|
||||||
val attachmentId = match[1].toLong()
|
var size = match[4].toFloatOrNull() ?: -1f
|
||||||
var size = match[2].toFloatOrNull() ?: -1f
|
when (match[5]) {
|
||||||
when (match[3]) {
|
"K" -> size *= 1024f
|
||||||
"K" -> size *= 1024f
|
"M" -> size *= 1024f * 1024f
|
||||||
"M" -> size *= 1024f * 1024f
|
"G" -> size *= 1024f * 1024f * 1024f
|
||||||
"G" -> size *= 1024f * 1024f * 1024f
|
|
||||||
}
|
|
||||||
message.addAttachment(attachmentId, attachmentName, size.toLong())
|
|
||||||
}
|
}
|
||||||
|
message.addAttachment(attachmentId, attachmentName, size.toLong())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,14 +33,14 @@ class MobidziennikWebHomework(override val data: DataMobidziennik,
|
|||||||
webGet(TAG, "/mobile/$endpoint") { text ->
|
webGet(TAG, "/mobile/$endpoint") { text ->
|
||||||
MobidziennikLuckyNumberExtractor(data, 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 tableRow = homeworkMatch[1].ifBlank { return@forEach }
|
||||||
|
|
||||||
/*val items = Regexes.MOBIDZIENNIK_HOMEWORK_ITEM.findAll(tableRow).map { match ->
|
/*val items = Regexes.MOBIDZIENNIK_HOMEWORK_ITEM.findAll(tableRow).map { match ->
|
||||||
match[1] to match[2].fixWhiteSpaces()
|
match[1] to match[2].fixWhiteSpaces()
|
||||||
}.toList()*/
|
}.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)
|
if (event.id != id)
|
||||||
return@forEach
|
return@forEach
|
||||||
|
|
||||||
@ -48,12 +48,13 @@ class MobidziennikWebHomework(override val data: DataMobidziennik,
|
|||||||
|
|
||||||
event.attachmentIds = mutableListOf()
|
event.attachmentIds = mutableListOf()
|
||||||
event.attachmentNames = 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.attachmentIds?.add(it[1].toLongOrNull() ?: return@forEach)
|
||||||
event.attachmentNames?.add(it[2])
|
event.attachmentNames?.add(it[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
event.homeworkBody = ""
|
event.homeworkBody = ""
|
||||||
|
event.isDownloaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
//data.eventList.add(eventObject)
|
//data.eventList.add(eventObject)
|
||||||
|
@ -57,6 +57,7 @@ class PodlasieApiEvents(val data: DataPodlasie, val rows: List<JsonObject>) {
|
|||||||
addedDate = addedDate
|
addedDate = addedDate
|
||||||
).apply {
|
).apply {
|
||||||
homeworkBody = description
|
homeworkBody = description
|
||||||
|
isDownloaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
|
@ -37,6 +37,7 @@ class PodlasieApiHomework(val data: DataPodlasie, val rows: List<JsonObject>) {
|
|||||||
addedDate = addedDate
|
addedDate = addedDate
|
||||||
).apply {
|
).apply {
|
||||||
homeworkBody = description
|
homeworkBody = description
|
||||||
|
isDownloaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
eventObject.attachmentIds = mutableListOf()
|
eventObject.attachmentIds = mutableListOf()
|
||||||
|
@ -164,6 +164,7 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va
|
|||||||
|
|
||||||
override fun getEvent(eventFull: EventFull) {
|
override fun getEvent(eventFull: EventFull) {
|
||||||
eventFull.homeworkBody = ""
|
eventFull.homeworkBody = ""
|
||||||
|
eventFull.isDownloaded = true
|
||||||
|
|
||||||
EventBus.getDefault().postSticky(EventGetEvent(eventFull))
|
EventBus.getDefault().postSticky(EventGetEvent(eventFull))
|
||||||
completed()
|
completed()
|
||||||
|
Loading…
Reference in New Issue
Block a user