add optional daily weekly and monathly events output
This commit is contained in:
parent
9aa923865b
commit
564bc640ef
2 changed files with 39 additions and 8 deletions
|
@ -36,6 +36,13 @@ http://localhost:8080/rss?ics=<ICS_URL>
|
|||
|
||||
Ersetze `<ICS_URL>` 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=<ICS_URL>`
|
||||
- Für heutige Events: `/rss?ics=<ICS_URL>&range=today`
|
||||
- Für Events dieser Woche: `/rss?ics=<ICS_URL>&range=week`
|
||||
- Für Events dieses Monats: `/rss?ics=<ICS_URL>&range=month`
|
||||
|
||||
## Docker Compose Datei
|
||||
|
||||
Hier ist der Inhalt der `docker-compose.yml` Datei:
|
||||
|
|
40
go/main.go
40
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")
|
||||
|
|
Loading…
Reference in a new issue