Update README.md

This commit is contained in:
jeffreydwalter 2018-09-22 14:44:21 -05:00 committed by GitHub
parent 542e59f9ea
commit 0aa3577234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,6 +49,7 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"sync"
"time" "time"
"github.com/jeffreydwalter/arlo-golang" "github.com/jeffreydwalter/arlo-golang"
@ -57,8 +58,6 @@ import (
const ( const (
USERNAME = "user@example.com" USERNAME = "user@example.com"
PASSWORD = "supersecretpassword" PASSWORD = "supersecretpassword"
oneDay = 24 * time.Hour
) )
func main() { func main() {
@ -73,7 +72,7 @@ func main() {
// At this point you're logged into Arlo. // At this point you're logged into Arlo.
now := time.Now() now := time.Now()
start := now.Add(-7 * oneDay) start := now.Add(-7 * 24 * time.Hour)
// Get all of the recordings for a date range. // Get all of the recordings for a date range.
library, err := arlo.GetLibrary(start, now) library, err := arlo.GetLibrary(start, now)
@ -82,8 +81,14 @@ func main() {
return return
} }
// We need to wait for all of the recordings to download.
var wg sync.WaitGroup
for _, recording := range *library { for _, recording := range *library {
// Let the wait group know about the go routine that we're about to run.
wg.Add(1)
// The go func() here makes this script download the files concurrently. // The go func() here makes this script download the files concurrently.
// If you want to download them serially for some reason, just remove the go func() call. // If you want to download them serially for some reason, just remove the go func() call.
go func() { go func() {
@ -98,9 +103,15 @@ func main() {
} else { } else {
log.Printf("Downloaded video %s from %s", recording.CreatedDate) log.Printf("Downloaded video %s from %s", recording.CreatedDate)
} }
// Mark this go routine as done in the wait group.
wg.Done()
}() }()
} }
// Wait here until all of the go routines are done.
wg.Wait()
// Delete all of the videos you just downloaded from the Arlo library. // Delete all of the videos you just downloaded from the Arlo library.
// Notice that you can pass the "library" object we got back from the GetLibrary() call. // Notice that you can pass the "library" object we got back from the GetLibrary() call.
if err := arlo.BatchDeleteRecordings(library); err != nil { if err := arlo.BatchDeleteRecordings(library); err != nil {