Implement exporting of activities.
authorFlorian Forster <ff@octo.it>
Wed, 24 Jan 2018 19:35:18 +0000 (20:35 +0100)
committerFlorian Forster <ff@octo.it>
Wed, 24 Jan 2018 19:35:18 +0000 (20:35 +0100)
gfitsync.go

index 3bd416f..eb3c953 100644 (file)
@@ -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 {