gcd_downloader/gokrazy.go

38 lines
883 B
Go
Raw Normal View History

2023-10-16 02:47:14 -07:00
//go:build gokrazy
2023-10-16 02:47:14 -07:00
package main
import (
"flag"
"log"
"os"
"time"
2023-10-16 03:05:21 -07:00
"github.com/antelman107/net-wait-go/wait"
"github.com/gokrazy/gokrazy"
2023-10-16 02:47:14 -07:00
)
func main() {
gokrazy.WaitForClock()
2023-10-16 03:05:21 -07:00
if !wait.New(wait.WithDeadline(time.Minute), wait.WithWait(time.Second), wait.WithBreak(time.Second)).Do([]string{"www.comics.org:443"}) {
log.Println("Failed to connect to www.comics.org")
os.Exit(1) // Exit code 1 will cause gokrazy to restart the service
}
2023-10-16 02:47:14 -07:00
flag.Parse()
if os.Getenv("GCD_USERNAME") == "" || os.Getenv("GCD_PASSWORD") == "" {
log.Println("Username and password not provided")
os.Exit(0)
}
for {
createDirs()
lastUpdate := getLatestDate()
if shouldUpdate(lastUpdate) {
download(lastUpdate)
2023-10-16 02:47:14 -07:00
log.Println("update complete, waiting 1h to check again")
} else {
log.Println("It's too early, waiting 1h to check again")
}
time.Sleep(time.Hour)
}
}