Add night checking and clean up Makefile

This commit is contained in:
2025-10-31 13:14:58 -04:00
parent 9eb48dca82
commit 364961a847
4 changed files with 23 additions and 3 deletions

View File

@ -18,7 +18,9 @@ install-macos:
# Build for the host system # Build for the host system
build: 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 # Cross-compile for macOS ARM64
build-macos-arm64: build-macos-arm64:

1
go.mod
View File

@ -8,6 +8,7 @@ require (
github.com/dustin/go-humanize v1.0.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/mattn/go-isatty v0.0.20 // 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/ncruces/go-strftime v0.1.9 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect

2
go.sum
View File

@ -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/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 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= 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 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=

19
main.go
View File

@ -11,6 +11,7 @@ import (
"strconv" "strconv"
"sync" "sync"
"time" "time"
"github.com/nathan-osman/go-sunrise"
_ "modernc.org/sqlite" _ "modernc.org/sqlite"
"gocv.io/x/gocv" "gocv.io/x/gocv"
@ -41,6 +42,12 @@ var (
lock sync.Mutex 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() { func main() {
initDB() initDB()
go backgroundCollector() go backgroundCollector()
@ -108,14 +115,22 @@ func estimateCloudCover(url string) (float64, error) {
} }
func backgroundCollector() { func backgroundCollector() {
lat, lon := 44.3897, -68.8040 // your location (New York example)
for { for {
cover, err := estimateCloudCover(imageURL) cover, err := estimateCloudCover(imageURL)
result := CloudResult{Timestamp: time.Now(), CloudCover: cover} result := CloudResult{Timestamp: time.Now(), CloudCover: cover}
if err != nil { if err != nil {
result.Error = err.Error() 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) time.Sleep(time.Duration(refreshSecs) * time.Second)
} }
} }