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.
|
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
|
## Docker Compose Datei
|
||||||
|
|
||||||
Hier ist der Inhalt der `docker-compose.yml` Datei:
|
Hier ist der Inhalt der `docker-compose.yml` Datei:
|
||||||
|
|
28
go/main.go
28
go/main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -18,6 +19,12 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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)
|
log.Printf("[INFO] Fetching ICS file from URL: %s\n", icsURL)
|
||||||
|
|
||||||
// ICS-Datei herunterladen
|
// ICS-Datei herunterladen
|
||||||
|
@ -39,12 +46,13 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) {
|
||||||
feed := &feeds.Feed{
|
feed := &feeds.Feed{
|
||||||
Title: "Converted Calendar Feed",
|
Title: "Converted Calendar Feed",
|
||||||
Link: &feeds.Link{Href: icsURL},
|
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(),
|
Created: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
now := time.Now()
|
||||||
for _, event := range parser.Events {
|
for _, event := range parser.Events {
|
||||||
// Dereferenziere event.Start, um den time.Time Wert zu erhalten
|
if shouldIncludeEvent(event, timeRange, now) {
|
||||||
item := &feeds.Item{
|
item := &feeds.Item{
|
||||||
Title: event.Summary,
|
Title: event.Summary,
|
||||||
Description: event.Description,
|
Description: event.Description,
|
||||||
|
@ -53,6 +61,7 @@ func convertICStoRSS(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
feed.Items = append(feed.Items, item)
|
feed.Items = append(feed.Items, item)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Println("[INFO] Generating RSS feed")
|
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")
|
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() {
|
func main() {
|
||||||
http.HandleFunc("/rss", convertICStoRSS)
|
http.HandleFunc("/rss", convertICStoRSS)
|
||||||
log.Println("[INFO] Server is running at :8080")
|
log.Println("[INFO] Server is running at :8080")
|
||||||
|
|
Loading…
Reference in a new issue