Skip to content

Instantly share code, notes, and snippets.

@bryanjhv
Created August 2, 2024 16:45
Show Gist options
  • Save bryanjhv/02aac87f293b8d18c3623ddd7f567a36 to your computer and use it in GitHub Desktop.
Save bryanjhv/02aac87f293b8d18c3623ddd7f567a36 to your computer and use it in GitHub Desktop.
package main
import (
"cmp"
"context"
"fmt"
"slices"
"time"
_ "github.com/joho/godotenv/autoload"
"google.golang.org/api/calendar/v3"
)
func main() {
ctx := context.Background()
svc, err := calendar.NewService(ctx)
if err != nil {
panic(err)
}
res, err := svc.Events.
List("es-419.pe#holiday@group.v.calendar.google.com").
Fields("items(summary,start(date))").
TimeMin(fmt.Sprintf("%d-01-01T00:00:00Z", time.Now().Year())).
TimeMax(fmt.Sprintf("%d-12-31T23:59:59Z", time.Now().Year())).
Do()
if err != nil {
panic(err)
}
slices.SortStableFunc(res.Items, func(a, b *calendar.Event) int {
return cmp.Compare(a.Start.Date+"|"+a.Summary, b.Start.Date+"|"+b.Summary)
})
for _, event := range res.Items {
fmt.Println(event.Start.Date, "|", event.Summary)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment