annotate calsync/event_sync.go @ 49:2991c1166852

start calsync in go. Calendar list seems to sync
author drewp@bigasterisk.com
date Mon, 19 Aug 2024 13:25:03 -0700
parents
children a9b720445bcf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
1 package main
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
2
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
3 import (
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
4 "log"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
5 "time"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
6
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
7 "bigasterisk.com/go/gcalendarwatch/convert"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
8 "bigasterisk.com/go/gcalendarwatch/gcalclient"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
9 "bigasterisk.com/go/gcalendarwatch/mongoclient"
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
10 )
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
11
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
12 func updateMongoEventsToMatchGoogle(mc *mongoclient.MongoClient, gc *gcalclient.GCalClient) error {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
13 t := time.Now()
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
14 events, err := gc.FindEvents(t)
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
15 if err != nil {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
16 return err
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
17 }
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
18 log.Println("Found", len(events), "events")
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
19 // todo: wipe mongo time period
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
20 log.Println("Upcoming events:")
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
21 for _, ev := range events {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
22 mc.UpsertOneEvent(convert.MongoEventFromGoogleEvent2(ev.CalendarUrl, ev, t))
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
23 }
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
24 return nil
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
25 }