From d2d7843b6f52e1c2ac8a4b499d90085f95250387 Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Tue, 21 Feb 2017 16:22:34 +1030 Subject: [PATCH] Show upload rate and speed --- dau.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/dau.go b/dau.go index c1745f3..017638d 100644 --- a/dau.go +++ b/dau.go @@ -16,7 +16,7 @@ import ( "io/ioutil" ) -var current_version = "0.3" +var current_version = "0.4" var last_check = time.Now() var new_last_check = time.Now() @@ -180,6 +180,7 @@ func process_file(file string) { if err != nil { log.Fatal(err) } + start := time.Now() client := &http.Client{ Timeout: time.Second * 30 } resp, err := client.Do(request) if err != nil { @@ -212,7 +213,11 @@ func process_file(file string) { return } var a = res.Attachments[0] - log.Printf("Uploaded to %s %dx%d, %d bytes\n", a.Url, a.Width, a.Height, a.Size) + elapsed := time.Since(start) + rate := float64(a.Size) / elapsed.Seconds() / 1024.0 + + log.Printf("Uploaded to %s %dx%d", a.Url, a.Width, a.Height) + log.Printf("%d bytes transferred in %.2f seconds (%.2f KiB/s)", a.Size, elapsed.Seconds(), rate) } }