Remove unused timetable classes

This commit is contained in:
Mikołaj Pich 2020-11-11 19:02:24 +01:00
parent 21541c9a6c
commit 07100af76c
3 changed files with 29 additions and 42 deletions

View file

@ -9,17 +9,20 @@ import io.github.wulkanowy.sdk.scrapper.toLocalDate
import org.jsoup.Jsoup
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 ->
val times = lessons[0].split("<br />")
TimetableResponse.TimetableRow.TimetableCell().apply {
date = headers.union(_headersOld).drop(1)[i].date.split("<br />")[1].toDate("dd.MM.yyyy")
start = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[1]}".toDate("yyyy-MM-dd HH:mm")
end = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[2]}".toDate("yyyy-MM-dd HH:mm")
number = times[0].toInt()
val date = headers.union(_headersOld).drop(1)[i].date.split("<br />")[1].toDate("dd.MM.yyyy")
TimetableCell(
date = date,
start = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[1]}".toDate("yyyy-MM-dd HH:mm"),
end = "${date.toLocalDate().toFormat("yyyy-MM-dd")} ${times[2]}".toDate("yyyy-MM-dd HH:mm"),
number = times[0].toInt(),
td = Jsoup.parse(it)
}
}.mapNotNull { TimetableParser().getTimetable(it) }
)
}.mapNotNull { parser.getTimetable(it) }
}.asSequence().filter {
it.date.toLocalDate() >= startDate && it.date.toLocalDate() <= endDate ?: startDate.plusDays(4)
}.sortedWith(compareBy({ it.date }, { it.number })).toList()

View file

@ -12,7 +12,7 @@ class TimetableParser {
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)
}

View file

@ -6,45 +6,29 @@ import org.jsoup.nodes.Element
import java.util.Date
@JsonClass(generateAdapter = true)
class TimetableResponse {
data class TimetableResponse(
@Json(name = "Header")
var _headersOld: List<Header> = emptyList()
val _headersOld: List<Header> = emptyList(),
@Json(name = "Headers")
var headers: List<Header> = emptyList()
val headers: List<Header> = emptyList(),
@Json(name = "Rows")
var rows2api: List<List<String>> = emptyList()
val rows: List<List<String>> = emptyList()
)
@JsonClass(generateAdapter = true)
class Header {
@JsonClass(generateAdapter = true)
data class Header(
@Json(name = "Text")
lateinit var date: String
}
@Json(name = "Text")
val date: String
)
class TimetableRow {
var number: Int = 0
lateinit var startTime: String
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
}
}
}
data class TimetableCell(
val number: Int = 0,
val start: Date,
val end: Date,
val date: Date,
val td: Element
)