Add night checking and clean up Makefile
This commit is contained in:
4
Makefile
4
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:
|
||||
|
||||
1
go.mod
1
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
|
||||
|
||||
2
go.sum
2
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=
|
||||
|
||||
15
main.go
15
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()
|
||||
}
|
||||
|
||||
|
||||
//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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user