This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
weserplaner/app/src/main/java/com/denizk0461/studip/data/StudIPParser.kt
T

49 lines
1.9 KiB
Kotlin
Raw Normal View History

package com.denizk0461.studip.data
import android.util.Log
import com.denizk0461.studip.model.StudIPEvent
import org.jsoup.Jsoup
class StudIPParser {
fun parse(html: String, insert: (events: List<StudIPEvent>) -> Unit) {
var id = 0
val doc = Jsoup.parse(html)
Log.d("HELLO2", "doc: $doc")
val newEvents = mutableListOf<StudIPEvent>()
val columns = arrayOf(
doc.getElementById("calendar_view_1_column_0"),
doc.getElementById("calendar_view_1_column_1"),
doc.getElementById("calendar_view_1_column_2"),
doc.getElementById("calendar_view_1_column_3"),
doc.getElementById("calendar_view_1_column_4"),
)
Log.d("HELLO2", "days found: ${columns.size}, element 1: ${columns[0]}")
columns.forEachIndexed { index, element ->
element?.getElementsByClass("schedule_entry")?.forEachIndexed { entryIndex, entry ->
Log.d("HELLO2", "element - $entryIndex - found: $entry")
val entryHeader = entry.getElementsByTag("dt")[0].text()
val delimiter = entryHeader.lastIndexOf('(')
val parsedTitle = entryHeader.substring(0 until delimiter)
val parsedLecturers = entryHeader.substring(delimiter + 1 until entryHeader.length - 1)
val entryInfos = entry.getElementsByTag("dd")[0].text().split(", ")
val timeSlot = DummyData.parseTimeslot(entryInfos[0])
val event = StudIPEvent(
id = id,
title = parsedTitle,
lecturer = parsedLecturers,
room = entryInfos[1],
day = index,
timeslotStart = timeSlot.first,
timeslotEnd = timeSlot.second,
)
newEvents.add(event)
id += 1
Log.d("HELLO2", event.toString())
}
}
insert(newEvents)
}
}