Skip to content

Instantly share code, notes, and snippets.

Last active September 17, 2021 14:36
Show Gist options
  • Save Eladkay/2d552b23942f6d199402be2fadbe8cfa to your computer and use it in GitHub Desktop.
Save Eladkay/2d552b23942f6d199402be2fadbe8cfa to your computer and use it in GitHub Desktop.
Easy interface for Technion courses in Kotlin.
import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
data class ScheduleItem(val group: String?, val number: String?, val type: String?, val lecturer: String?, val day: String?,
val hours: String?, val building: String?, val room: String?)
data class Course(val faculty: String?, val name: String?, val number: String?, val pts: Double?,
val lectureHours: Int?, val recitationHours: Int?, val labHours: Int?, val seminarHours: Int?,
val syllabus: String?, val prerequisites: String?, val adjacent: String?, val noAdditionalCredit: String?,
val identical: String?, val containing: String?, val contained: String?, val responsible: String?,
val comments: String?, val schedule: List<ScheduleItem>)
data class CourseBase(val general: Map<String, String>, val schedule: List<Map<String, String>>) {
fun toCourse(): Course {
val faculty = general["פקולטה"]
val name = general["שם מקצוע"]
val number = general["מספר מקצוע"]
val pts = general["נקודות"]?.toDoubleOrNull()
val lectureHours = general["הרצאה"]?.toIntOrNull()
val recitationHours = general["תרגיל"]?.toIntOrNull()
val labHours = general["מעבדה"]?.toIntOrNull()
val seminarHours = general["פרויקט\\/סמינר"]?.toIntOrNull()
val syllabus = general["סילבוס"]
val prerequisites = general["מקצועות קדם"]
val adjacent = general["מקצועות צמודים"]
val noAdditionalCredit = general["מקצועות ללא זיכוי נוסף"]
val identical = general["מקצועות זהים"]
val containing = general["מקצועות ללא זיכוי נוסף (מכילים)"]
val contained = general["מקצועות ללא זיכוי נוסף (מוכלים)"]
val responsible = general["אחראים"]
val comments = general["הערות"]
val schedule = {
val group = it["קבוצה"]
val groupNumber = it["מס."]
val type = it["סוג"]
val lecturer = it["מרצה\\/מתרגל"]
val day = it["יום"]
val hours = it["שעה"]
val building = it["בניין"]
val room = it["חדר"]
ScheduleItem(group, groupNumber, type, lecturer, day, hours, building, room)
return Course(faculty, name, number, pts, lectureHours, recitationHours, labHours, seminarHours, syllabus, prerequisites, adjacent, noAdditionalCredit, identical, containing, contained, responsible, comments, schedule)
private val courses by lazy { loadCourses() }
fun getAllCourses(): List<Course> = courses.toList()
private fun loadCourses(): List<Course> {
val text = URL("$semester.min.js").readText()
.removePrefix("var courses_from_rishum = ")
val coursesBase = Json.decodeFromString<List<CourseBase>>(text)
return { it.toCourse() }
val semester = "202002"
fun main() {
println(courses.filterNot { course-> (2 until course.number!!.toInt()).any { it % course.number.toInt() == 0 } }[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment