io.github.wulkanowy.sdk.scrapper.homework.HomeworkMapper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-scrapper Show documentation
Show all versions of sdk-scrapper Show documentation
Unified way of retrieving data from the UONET+ register through mobile api and scraping api
package io.github.wulkanowy.sdk.scrapper.homework
import org.jsoup.parser.Parser
import java.time.LocalDate
internal fun List.mapHomework(startDate: LocalDate, endDate: LocalDate?): List {
val end = endDate ?: startDate
return asSequence().map { day ->
day.items.map { homework ->
val teacherAndCode = homework.teacher.split(", ").first().split(" [")
val teacher = teacherAndCode.first()
val teacherCode = teacherAndCode.last().removeSuffix("]")
homework.copy(
teacher = teacher,
date = day.date,
content = Parser.unescapeEntities(homework.content, true),
).apply {
teacherSymbol = teacherCode
_attachments = homework.attachments.map { it.url to it.filename }
}
}
}.flatten().filter {
it.date.toLocalDate() in startDate..end
}.sortedWith(compareBy({ it.date }, { it.subject })).toList()
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy