Created
August 2, 2024 16:45
-
-
Save bryanjhv/02aac87f293b8d18c3623ddd7f567a36 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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#[email protected]"). | |
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