From d5ea2b2ae8ee6d49c56a6c9b93dcf58d490dbd89 Mon Sep 17 00:00:00 2001 From: githubert Date: Mon, 17 Sep 2012 00:51:12 +0200 Subject: Zorn shall be off at night! --- ausgezornt.go | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ausgezornt.go (limited to 'ausgezornt.go') diff --git a/ausgezornt.go b/ausgezornt.go new file mode 100644 index 0000000..26a7e29 --- /dev/null +++ b/ausgezornt.go @@ -0,0 +1,62 @@ +package main + +// YEAH YEAH CARGO CULT PROGRAMMING +// *HACK* *HACK* *COPY* *HACK* + +import ( + "flag" + "fmt" + "time" + "net/http" + "log" + "encoding/json" + "os/exec" +) + +type Clubinfo struct { + Last_event string + Club_offen bool +} + +func main() { + // WAAAAAH! + var url = flag.String("url", "http://club.entropia.de", "Target URL for JSON data") + var timeout = flag.Int("timeout", 1, "Timeout in hours") + var dryrun = flag.Bool("dryrun", false, "Dry run") + + flag.Parse() + + resp, err := http.Get(*url) + + if err != nil { + log.Fatal(err) + } + + defer resp.Body.Close() + + // WAAAAAAAAHAAAAAA! + decoder := json.NewDecoder(resp.Body) + + var c Clubinfo + err = decoder.Decode(&c) + + if err != nil { + log.Fatal(err) + } + + // RFC3339 without ':' for time zone foooooo + last, _ := time.Parse("2006-01-02T15:04:05Z0700", c.Last_event) + + // WAAAAABWHARGLGLRELRLLLllmn... + if time.Since(last).Hours() > float64(*timeout) { + if !c.Club_offen { + if !*dryrun { + cmd := exec.Command("shutdown", "-h +5") + cmd.Start() + } else { + fmt.Println("I advise against letting this machine run any longer."); + } + } + } +} + -- cgit