From 364961a8470c4db7c4577eb3e1fbbef489bc6359 Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Fri, 31 Oct 2025 13:14:58 -0400 Subject: [PATCH] Add night checking and clean up Makefile --- Makefile | 4 +++- go.mod | 1 + go.sum | 2 ++ main.go | 19 +++++++++++++++++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8d4c18b..f218dc1 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,9 @@ install-macos: # Build for the host system build: - go build -o build/$(BINARY_NAME) . + export CGO_CPPFLAGS="$(pkg-config --cflags opencv4)" + export CGO_LDFLAGS="$(pkg-config --libs opencv4 | sed 's/-lopencv_hdf//g' | sed 's/-lopencv_viz//g')" + go build -tags customenv -o build/$(BINARY_NAME) . # Cross-compile for macOS ARM64 build-macos-arm64: diff --git a/go.mod b/go.mod index 8a272a7..70ade86 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/nathan-osman/go-sunrise v1.1.0 // indirect github.com/ncruces/go-strftime v0.1.9 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect diff --git a/go.sum b/go.sum index 729bf75..6203a8c 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/nathan-osman/go-sunrise v1.1.0 h1:ZqZmtmtzs8Os/DGQYi0YMHpuUqR/iRoJK+wDO0wTCw8= +github.com/nathan-osman/go-sunrise v1.1.0/go.mod h1:RcWqhT+5ShCZDev79GuWLayetpJp78RSjSWxiDowmlM= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/main.go b/main.go index e371db4..635df0e 100644 --- a/main.go +++ b/main.go @@ -11,6 +11,7 @@ import ( "strconv" "sync" "time" + "github.com/nathan-osman/go-sunrise" _ "modernc.org/sqlite" "gocv.io/x/gocv" @@ -41,6 +42,12 @@ var ( lock sync.Mutex ) +func isNight(lat, lon float64) bool { + now := time.Now() + sunriseTime, sunsetTime := sunrise.SunriseSunset(lat, lon, now.Year(), now.Month(), now.Day()) + return now.Before(sunriseTime) || now.After(sunsetTime) +} + func main() { initDB() go backgroundCollector() @@ -108,14 +115,22 @@ func estimateCloudCover(url string) (float64, error) { } func backgroundCollector() { + lat, lon := 44.3897, -68.8040 // your location (New York example) for { cover, err := estimateCloudCover(imageURL) result := CloudResult{Timestamp: time.Now(), CloudCover: cover} if err != nil { result.Error = err.Error() } - storeResult(result) - fmt.Printf("[%s] Cloud cover: %.2f%%\n", result.Timestamp.Format("15:04:05"), result.CloudCover) + + + //lat, lon := 40.7128, -74.0060 // your location (New York example) + if !isNight(lat, lon) { + storeResult(result) + fmt.Printf("[%s] Cloud cover: %.2f%%\n", result.Timestamp.Format("15:04:05"), result.CloudCover) + } else { + fmt.Println("🌙 It's night — skipping cloud capture") + } time.Sleep(time.Duration(refreshSecs) * time.Second) } }