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

19
main.go
View File

@ -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)
}
}