Mercurial > code > home > repos > gcalendarwatch
diff calsync/main.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 | 627c815f83bb |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/calsync/main.go Mon Aug 19 13:25:03 2024 -0700 @@ -0,0 +1,87 @@ +package main + +/* +let python continue to serve these: + Route('/', getRoot), + Route('/graph/calendar/upcoming', StaticGraph(agendaGraph)), + use https://github.com/cayleygraph/quad + Route('/graph/calendar/upcoming/events', GraphEvents(agendaGraph)), + use https://github.com/tmaxmax/go-sse + Route('/graph/calendar/countdown', StaticGraph(countdownGraph)), + Route('/graph/calendar/countdown/events', GraphEvents(countdownGraph)), + Route('/graph/currentEvents', StaticGraph(currentEventsGraph)), + Route('/graph/currentEvents/events', GraphEvents(currentEventsGraph)), +*/ + +import ( + "context" + "log" + "net/http" + + "bigasterisk.com/go/gcalendarwatch/gcalclient" + "bigasterisk.com/go/gcalendarwatch/mongoclient" + "github.com/gorilla/mux" +) + +func main() { + ctx := context.Background() + + log.SetFlags(log.LstdFlags | log.Lshortfile) + gc, err := gcalclient.New(ctx) + if err != nil { + log.Fatal(err) + } + defer gc.Close() + + mc, err := mongoclient.New(ctx) + if err != nil { + log.Fatal(err) + } + defer mc.Close() + + err = updateMongoCalsToMatchGoogle(mc, gc) + if err != nil { + log.Fatal(err) + } + + err = updateMongoEventsToMatchGoogle(mc, gc) + if err != nil { + log.Fatal(err) + } + + /* + ------------------ + connect to mongodb with these ops: + save cals list + get/set incremental token + add/edit/del events + collection.find({"startTime": {"$gte": t1, "$lt": t2}}).sort([("startTime", 1)]) + collection.find({"startTime": {"$lte": now}, "endTime": {"$gte": now}})) + + connect to https://github.com/googleapis/google-api-go-client/tree/main/calendar/v3 and: + get all my cals + + subscribe to events + + get cal event changes from incremental token + + get cal events in range, for initial fill? + + write add/edit/del changes to mongo + */ + + r := mux.NewRouter() + http.Handle("/", r) + + home := func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("calsync service for calendar updates")) + } + r.HandleFunc("/", home) + r.HandleFunc("/gcalendarwatch", home) + + notificationHandler := func(w http.ResponseWriter, r *http.Request) { + } + r.HandleFunc("/gcalendarwatch/notification", notificationHandler).Methods("POST") + log.Println(("serving /gcalendarwatch/notification on :8080")) + log.Fatal(http.ListenAndServe(":8080", nil)) +}