-
Notifications
You must be signed in to change notification settings - Fork 8
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
paul-em
wants to merge
4
commits into
boudicca-events:main
Choose a base branch
from
paul-em:eventcollectors/familienkarte
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../src/main/kotlin/events/boudicca/eventcollector/collectors/FamilienkarteEventCollector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")) | ||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use ISO_DATE_TIME here |
||
} | ||
data[SemanticKeys.TYPE] = "other" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(), | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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