Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jecnaapi-canteen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ kotlin {
}
val iosMain by getting
iosMain.dependencies {
runtimeOnly(libs.ktor.client.engine.darwin)
implementation(libs.ktor.client.engine.darwin)
}
jsMain.dependencies {
runtimeOnly(libs.ktor.client.engine.js)
Expand Down
2 changes: 1 addition & 1 deletion jecnaapi-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ kotlin {
}
val iosMain by getting
iosMain.dependencies {
runtimeOnly(libs.ktor.client.engine.darwin)
implementation(libs.ktor.client.engine.darwin)
}
jsMain.dependencies {
runtimeOnly(libs.ktor.client.engine.js)
Expand Down
2 changes: 1 addition & 1 deletion jecnaapi-jecna/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ kotlin {
}
val iosMain by getting
iosMain.dependencies {
runtimeOnly(libs.ktor.client.engine.darwin)
implementation(libs.ktor.client.engine.darwin)
}
jsMain.dependencies {
runtimeOnly(libs.ktor.client.engine.js)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.tomhula.jecnaapi.data.grade

import io.github.tomhula.jecnaapi.data.schoolStaff.TeacherReference
import kotlinx.serialization.Serializable
import io.github.tomhula.jecnaapi.util.Name
import kotlinx.datetime.LocalDate

/**
Expand All @@ -15,7 +15,7 @@ import kotlinx.datetime.LocalDate
data class Grade(
val value: Int,
val small: Boolean,
val teacher: Name? = null,
val teacher: TeacherReference? = null,
val description: String? = null,
val receiveDate: LocalDate? = null,
val gradeId: Int
Expand All @@ -29,7 +29,7 @@ data class Grade(
constructor(
valueChar: Char,
small: Boolean,
teacher: Name? = null,
teacher: TeacherReference? = null,
description: String? = null,
receiveDate: LocalDate? = null,
gradeId: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.github.tomhula.jecnaapi.data.schoolStaff

import io.github.tomhula.jecnaapi.data.SchoolAttendee
import io.github.tomhula.jecnaapi.data.cert.Certificate
import io.github.tomhula.jecnaapi.data.room.RoomReference
import io.github.tomhula.jecnaapi.data.timetable.Timetable

class Teacher(
Expand All @@ -14,7 +15,7 @@ class Teacher(
tag: String,
val privatePhoneNumber: String? = null,
val landline: String? = null,
val cabinet: String? = null,
val cabinet: RoomReference? = null,
val tutorOfClass: String? = null,
val consultationHours: String? = null,
val timetable: Timetable? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.github.tomhula.jecnaapi.util.SchoolYearHalf
import com.fleeksoft.ksoup.Ksoup
import com.fleeksoft.ksoup.nodes.Document
import com.fleeksoft.ksoup.nodes.Element
import io.github.tomhula.jecnaapi.data.schoolStaff.TeacherReference
import kotlinx.datetime.LocalDate

/** https://www.spsejecna.cz/score/student */
Expand Down Expand Up @@ -175,7 +176,7 @@ internal object GradesPageParser
val receiveDate = detailsMatch.groups[GradeDetailsRegexGroups.DATE]!!.value.let { LocalDate.parse(it, CommonParser.CZECH_DATE_FORMAT_WITH_PADDING) }
val teacherFull = detailsMatch.groups[GradeDetailsRegexGroups.TEACHER]!!.value

val teacherName = Name(teacherFull, teacherShort)
val teacherName = TeacherReference(teacherFull, teacherShort)

return Grade(valueChar, small, teacherName, description, receiveDate, gradeId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.tomhula.jecnaapi.parser.parsers
import com.fleeksoft.ksoup.Ksoup
import com.fleeksoft.ksoup.nodes.Element
import io.github.tomhula.jecnaapi.data.cert.Certificate
import io.github.tomhula.jecnaapi.data.room.RoomReference
import io.github.tomhula.jecnaapi.data.schoolStaff.Teacher
import io.github.tomhula.jecnaapi.parser.ParseException
import kotlinx.datetime.LocalDate
Expand All @@ -16,18 +17,28 @@ internal class TeacherParser(private val timetableParser: TimetableParser)
{
val document = Ksoup.parse(html)
val table = document.selectFirstOrThrow(".userprofile", "data table")
val fullName = getTableValue(table, "Jméno")!!
val tag = getTableValue(table, "Zkratka")!!
val username = getTableValue(table, "Uživatelské jméno")!!
val schoolMail = getTableValue(table, "E-mail")!!
val privateMail = getTableValue(table, "Soukromý e-mail")
val phoneColumn = getTableValue(table, "Telefon")
val fullName = getTableValueText(table, "Jméno")!!
val tag = getTableValueText(table, "Zkratka")!!
val username = getTableValueText(table, "Uživatelské jméno")!!
val schoolMail = getTableValueText(table, "E-mail")!!
val privateMail = getTableValueText(table, "Soukromý e-mail")
val phoneColumn = getTableValueText(table, "Telefon")
val phoneNumbers = phoneColumn?.let { phoneCol -> PHONE_NUMBER_REGEX.findAll(phoneCol).map { it.value }.toList() } ?: emptyList()
val landline = phoneColumn?.let { phoneCol -> LAND_LINE_REGEX.find(phoneCol)?.value }
val privatePhone = getTableValue(table, "Soukromý telefon")
val cabinet = getTableValue(table, "Kabinet")
val consultationHours = getTableValue(table, "Konzultační hodiny")
val tutorOfClass = getTableValue(table, "Třídní učitel")
val privatePhone = getTableValueText(table, "Soukromý telefon")

val cabinetName = getTableValueText(table, "Kabinet")
val cabinetHref = getTableValueHref(table, "Kabinet")
?.substringAfter("/ucebna/")
?.takeIf { it.isNotBlank() }
val cabinet = if (cabinetName != null && cabinetHref != null) {
RoomReference(cabinetName, cabinetHref)
} else {
null
}

val consultationHours = getTableValueText(table, "Konzultační hodiny")
val tutorOfClass = getTableValueText(table, "Třídní učitel")
val profilePicturePath = document.selectFirst(".profilephoto .image img")?.attr("src")
val timetableEle = document.selectFirst("table.timetable")
val timetable = timetableEle?.let { timetableParser.parse(it.outerHtml()) }
Expand Down Expand Up @@ -71,13 +82,23 @@ internal class TeacherParser(private val timetableParser: TimetableParser)
throw ParseException("Failed to parse teacher.", e)
}
}

private fun getTableValue(table: Element, key: String): String?
private fun getTableValue(table: Element, key: String): Element?
{
val rows = table.select("tr")
val targetRow = rows.find { row -> row.selectFirst(".label")?.let { it.text() == key } ?: false }

return targetRow?.selectFirst(".value,.link")?.text()
return targetRow?.selectFirst(".value,.link")
}

private fun getTableValueText(table: Element, key: String): String?
{
return getTableValue(table, key)?.text()
}

private fun getTableValueHref(table: Element, key: String): String?
{
return getTableValue(table, key)?.attr("href")
}

companion object
Expand Down