view calsync/sync_cal.go @ 79:30ad34850ef1

redo url structure (still not the same as the old version)
author drewp@bigasterisk.com
date Fri, 06 Sep 2024 18:24:38 -0700
parents 19e3def953e1
children
line wrap: on
line source

package main

import (
	"log"

	"bigasterisk.com/go/gcalendarwatch/convert"
	"bigasterisk.com/go/gcalendarwatch/gcalclient"
	"bigasterisk.com/go/gcalendarwatch/mongoclient"
	M "bigasterisk.com/go/gcalendarwatch/mongoclienttypes"
)

func updateMongoCalsToMatchGoogleOnce(mc *mongoclient.MongoClient, gc *gcalclient.GCalClient) (err error) {
	log.Println("updateMongoCalsToMatchGoogle")

	seen := make(map[string]bool)

	cals, err := gc.AllCalendars()
	if err != nil {
		return err
	}

	for _, serviceCal := range cals {
		cal := convert.MongoCalFromGoogleCal(serviceCal)
		log.Println(M.Prefix(cal), "syncing calendar doc")
		seen[cal.Url] = true
		err = mc.UpsertOneCal(cal)
		if err != nil {
			return err
		}
	}

	err = mc.DeleteCalsNotInSet(seen)

	log.Println("updateMongoCalsToMatchGoogle done")
	return err
}