Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup basic familienkarte event collector #116

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@ fun main() {
.addEventCollector(EnnsEventsCollector())
.addEventCollector(UlfOoeCollector())
.addEventCollector(StiftskonzerteCollector())
.addEventCollector(FamilienkarteCollector())
.run()
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ fun main() {
// .debug(OteloLinzCollector())
// .debug(EnnsEventsCollector())
// .debug(UlfOoeCollector())
.debug(StiftskonzerteCollector())
// .debug(StiftskonzerteCollector())
.debug(FamilienkarteCollector())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package events.boudicca.eventcollector.collectors

import events.boudicca.SemanticKeys
import events.boudicca.api.eventcollector.Event
import events.boudicca.api.eventcollector.Fetcher
import events.boudicca.api.eventcollector.TwoStepEventCollector
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import java.time.LocalDate
import java.time.LocalTime
import java.time.OffsetDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter

class FamilienkarteCollector : TwoStepEventCollector<String>("familienkarte") {

private val fetcher = Fetcher()


override fun getAllUnparsedEvents(): List<String> {
val document = Jsoup.parse(fetcher.fetchUrl("https://www.familienkarte.at/de/freizeit/veranstaltungen/veranstaltungskalender.html?events_cat_key=8"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short question about the url. why limit it to events from category 8? also, i saw that by default the page only shows events from today, we should extend that so we get more events from them

return document.select("div.detailButton a")
.map { it.attr("href") }
}

override fun parseEvent(event: String): Event {
val eventSite = Jsoup.parse(fetcher.fetchUrl(event))

val name = eventSite.select("div.eventDetailWrapper h1").text()
val (startDate, endDate) = parseDates(eventSite)

val data = mutableMapOf<String, String>()
data[SemanticKeys.URL] = event
if (endDate != null) {
data[SemanticKeys.ENDDATE] = endDate.format(DateTimeFormatter.ISO_DATE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use ISO_DATE_TIME here

}
data[SemanticKeys.TYPE] = "other"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type other does not really make sense, if you don't have any information on the type of event just don't add it :)

data[SemanticKeys.DESCRIPTION] = eventSite.select("div.eventDetailDescr").text()

val img = eventSite.select("div.eventEntry img")
if (!img.isEmpty()) {
data[SemanticKeys.PICTUREURL] = img.first()!!.attr("src")
}

data[SemanticKeys.LOCATION_NAME] = eventSite.select("div.eventDetailLocation").text()

return Event(name, startDate, data)
}


private fun parseDates(element: Element): Pair<OffsetDateTime, OffsetDateTime?> {
val fullDate = element.select("div.eventDetailWrapper h2").text()
val date = fullDate.substring(3, 11)
val localDate = LocalDate.parse(date, DateTimeFormatter.ofPattern("dd.MM.uu"))

val startAndEndTimeText = fullDate.substring(14, 27)
val startAndEndTimes = startAndEndTimeText.split(" - ")

val localStartTime = LocalTime.parse(startAndEndTimes[0].trim(), DateTimeFormatter.ofPattern("kk:mm"))
val localEndTime = LocalTime.parse(startAndEndTimes[1].trim(), DateTimeFormatter.ofPattern("kk:mm"))

return Pair(
localDate.atTime(localStartTime).atZone(ZoneId.of("Europe/Vienna")).toOffsetDateTime(),
localDate.atTime(localEndTime).atZone(ZoneId.of("Europe/Vienna")).toOffsetDateTime(),
)
}
}