Remove unused timetable classes
This commit is contained in:
parent
21541c9a6c
commit
07100af76c
3 changed files with 29 additions and 42 deletions
|
@ -9,17 +9,20 @@ import io.github.wulkanowy.sdk.scrapper.toLocalDate
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import java.time.LocalDate
|
import java.time.LocalDate
|
||||||
|
|
||||||
fun TimetableResponse.mapTimetableList(startDate: LocalDate, endDate: LocalDate?) = rows2api.flatMap { lessons ->
|
private val parser = TimetableParser()
|
||||||
|
|
||||||
|
fun TimetableResponse.mapTimetableList(startDate: LocalDate, endDate: LocalDate?) = rows.flatMap { lessons ->
|
||||||
lessons.drop(1).mapIndexed { i, it ->
|
lessons.drop(1).mapIndexed { i, it ->
|
||||||
val times = lessons[0].split("<br />")
|
val times = lessons[0].split("<br />")
|
||||||
TimetableResponse.TimetableRow.TimetableCell().apply {
|
val date = headers.union(_headersOld).drop(1)[i].date.split("<br />")[1].toDate("dd.MM.yyyy")
|
||||||
date = headers.union(_headersOld).drop(1)[i].date.split("<br />")[1].toDate("dd.MM.yyyy")
|
TimetableCell(
|
||||||
start = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[1]}".toDate("yyyy-MM-dd HH:mm")
|
date = date,
|
||||||
end = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[2]}".toDate("yyyy-MM-dd HH:mm")
|
start = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[1]}".toDate("yyyy-MM-dd HH:mm"),
|
||||||
number = times[0].toInt()
|
end = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[2]}".toDate("yyyy-MM-dd HH:mm"),
|
||||||
|
number = times[0].toInt(),
|
||||||
td = Jsoup.parse(it)
|
td = Jsoup.parse(it)
|
||||||
}
|
)
|
||||||
}.mapNotNull { TimetableParser().getTimetable(it) }
|
}.mapNotNull { parser.getTimetable(it) }
|
||||||
}.asSequence().filter {
|
}.asSequence().filter {
|
||||||
it.date.toLocalDate() >= startDate && it.date.toLocalDate() <= endDate ?: startDate.plusDays(4)
|
it.date.toLocalDate() >= startDate && it.date.toLocalDate() <= endDate ?: startDate.plusDays(4)
|
||||||
}.sortedWith(compareBy({ it.date }, { it.number })).toList()
|
}.sortedWith(compareBy({ it.date }, { it.number })).toList()
|
||||||
|
|
|
@ -12,7 +12,7 @@ class TimetableParser {
|
||||||
const val CLASS_MOVED_OR_CANCELED = "x-treelabel-inv"
|
const val CLASS_MOVED_OR_CANCELED = "x-treelabel-inv"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTimetable(c: TimetableResponse.TimetableRow.TimetableCell): Timetable? {
|
fun getTimetable(c: TimetableCell): Timetable? {
|
||||||
return addLessonDetails(Timetable(c.number, c.start, c.end, c.date), c.td)
|
return addLessonDetails(Timetable(c.number, c.start, c.end, c.date), c.td)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,45 +6,29 @@ import org.jsoup.nodes.Element
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
class TimetableResponse {
|
data class TimetableResponse(
|
||||||
|
|
||||||
@Json(name = "Header")
|
@Json(name = "Header")
|
||||||
var _headersOld: List<Header> = emptyList()
|
val _headersOld: List<Header> = emptyList(),
|
||||||
|
|
||||||
@Json(name = "Headers")
|
@Json(name = "Headers")
|
||||||
var headers: List<Header> = emptyList()
|
val headers: List<Header> = emptyList(),
|
||||||
|
|
||||||
@Json(name = "Rows")
|
@Json(name = "Rows")
|
||||||
var rows2api: List<List<String>> = emptyList()
|
val rows: List<List<String>> = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
class Header {
|
data class Header(
|
||||||
|
|
||||||
@Json(name = "Text")
|
@Json(name = "Text")
|
||||||
lateinit var date: String
|
val date: String
|
||||||
}
|
)
|
||||||
|
|
||||||
class TimetableRow {
|
data class TimetableCell(
|
||||||
|
val number: Int = 0,
|
||||||
var number: Int = 0
|
val start: Date,
|
||||||
|
val end: Date,
|
||||||
lateinit var startTime: String
|
val date: Date,
|
||||||
|
val td: Element
|
||||||
lateinit var endTime: String
|
)
|
||||||
|
|
||||||
var lessons: List<TimetableCell> = emptyList()
|
|
||||||
|
|
||||||
class TimetableCell {
|
|
||||||
|
|
||||||
var number: Int = 0
|
|
||||||
|
|
||||||
lateinit var start: Date
|
|
||||||
|
|
||||||
lateinit var end: Date
|
|
||||||
|
|
||||||
lateinit var date: Date
|
|
||||||
|
|
||||||
lateinit var td: Element
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue