annotate calsync/event_sync.go @ 51:a9b720445bcf

now roughly syncs cals and events to mongodb, one time
author drewp@bigasterisk.com
date Mon, 19 Aug 2024 14:42:27 -0700
parents 2991c1166852
children 5f7c393577e9
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
51
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
12 func updateMongoEventsToMatchGoogle(
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
13 mc *mongoclient.MongoClient, gc *gcalclient.GCalClient) error {
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
14 t := time.Now()
51
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
15 events, err := gc.FindEvents(mc, t, 3)
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
16 if err != nil {
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
17 return err
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
18 }
51
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
19 log.Println("upserting", len(events), "events")
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
20 for _, ev := range events {
51
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
21 mc.UpsertOneEvent(
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
22 convert.MongoEventFromGoogleEvent2(ev.CalendarUrl, ev, t),
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
23 )
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
24 }
51
a9b720445bcf now roughly syncs cals and events to mongodb, one time
drewp@bigasterisk.com
parents: 49
diff changeset
25 mc.DeleteEventsUpdatedBefore(t)
49
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
26 return nil
2991c1166852 start calsync in go. Calendar list seems to sync
drewp@bigasterisk.com
parents:
diff changeset
27 }