From: Florian Forster Date: Wed, 24 Jan 2018 19:35:18 +0000 (+0100) Subject: Implement exporting of activities. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=19a78ce4b915845cf1232c84f17074982f27a4ce;p=kraftakt.git Implement exporting of activities. --- diff --git a/gfitsync.go b/gfitsync.go index 3bd416f..eb3c953 100644 --- a/gfitsync.go +++ b/gfitsync.go @@ -314,6 +314,35 @@ func handleNotification(ctx context.Context, s *fitbit.Subscription) error { wg.Done() }() + wg.Add(1) + go func() { + defer wg.Done() + + var activities []gfit.Activity + for _, a := range summary.Activities { + if !a.HasStartTime { + continue + } + + startTime, err := time.ParseInLocation("2006-01-02T15:04:05", a.StartDate+"T"+a.StartTime, profile.Timezone) + if err != nil { + errs = append(errs, fmt.Errorf("gfitClient.SetActivities() = %v", err)) + return + } + endTime := startTime.Add(time.Duration(a.Duration) * time.Millisecond) + + activities = append(activities, gfit.Activity{ + Start: startTime, + End: endTime, + Type: gfit.ParseFitbitActivity(a.Name), + }) + } + if err := gfitClient.SetActivities(ctx, activities, tm); err != nil { + errs = append(errs, fmt.Errorf("gfitClient.SetActivities() = %v", err)) + return + } + }() + wg.Wait() if len(errs) != 0 {