diff --git a/README.md b/README.md index c17a241..7cf6d89 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,13 @@ http://localhost:8080/rss?ics= Ersetze `` durch die URL deiner ICS-Datei. +Und Optional wenn nur die Events des heutigen Tages, Woche, oder Monats ausgegeben werden soll: + +- Für alle Events: `/rss?ics=` +- Für heutige Events: `/rss?ics=&range=today` +- Für Events dieser Woche: `/rss?ics=&range=week` +- Für Events dieses Monats: `/rss?ics=&range=month` + ## Docker Compose Datei Hier ist der Inhalt der `docker-compose.yml` Datei: diff --git a/go/main.go b/go/main.go index 0c4c24c..e237302 100644 --- a/go/main.go +++ b/go/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "net/http" "time" @@ -18,6 +19,12 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) { return } + // Lese den Zeitraum aus dem Query-Parameter + timeRange := r.URL.Query().Get("range") + if timeRange == "" { + timeRange = "all" // Standardwert, wenn kein Zeitraum angegeben ist + } + log.Printf("[INFO] Fetching ICS file from URL: %s\n", icsURL) // ICS-Datei herunterladen @@ -39,19 +46,21 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) { feed := &feeds.Feed{ Title: "Converted Calendar Feed", Link: &feeds.Link{Href: icsURL}, - Description: "This is a converted calendar feed", + Description: fmt.Sprintf("This is a converted calendar feed for %s", timeRange), Created: time.Now(), } + now := time.Now() for _, event := range parser.Events { - // Dereferenziere event.Start, um den time.Time Wert zu erhalten - item := &feeds.Item{ - Title: event.Summary, - Description: event.Description, - Link: &feeds.Link{Href: icsURL}, - Created: *event.Start, + if shouldIncludeEvent(event, timeRange, now) { + item := &feeds.Item{ + Title: event.Summary, + Description: event.Description, + Link: &feeds.Link{Href: icsURL}, + Created: *event.Start, + } + feed.Items = append(feed.Items, item) } - feed.Items = append(feed.Items, item) } log.Println("[INFO] Generating RSS feed") @@ -70,6 +79,21 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) { log.Println("[INFO] RSS feed successfully generated and sent") } +func shouldIncludeEvent(event gocal.Event, timeRange string, now time.Time) bool { + switch timeRange { + case "today": + return event.Start.Year() == now.Year() && event.Start.YearDay() == now.YearDay() + case "week": + _, thisWeek := now.ISOWeek() + _, eventWeek := event.Start.ISOWeek() + return event.Start.Year() == now.Year() && eventWeek == thisWeek + case "month": + return event.Start.Year() == now.Year() && event.Start.Month() == now.Month() + default: + return true // "all" oder jeder andere Wert zeigt alle Ereignisse + } +} + func main() { http.HandleFunc("/rss", convertICStoRSS) log.Println("[INFO] Server is running at :8080")