diff --git a/main.go b/main.go index d2c4680..10306dc 100644 --- a/main.go +++ b/main.go @@ -69,8 +69,33 @@ func main() { for { // Main program loop refreshData() - log.Print("Sleeping for 6 hours...") - time.Sleep(time.Hour * 6) + + // Update at 59 minutes on the hour + + // Get current time + now := time.Now() + + // Calculate the next time at 59 minutes + next := time.Date( + now.Year(), + now.Month(), + now.Day(), + now.Hour(), + 59, + 0, + 0, + now.Location(), + ) + + // If we've already passed this hour's 59th minute, go to next hour + if !next.After(now) { + next = next.Add(time.Hour) + } + // Duration to sleep + duration := time.Until(next) + log.Printf("Sleeping until %v (%v)", next, duration) + + time.Sleep(duration) } }