diff options
author | githubert <ikseno@googlemail.com> | 2012-09-17 00:51:12 +0200 |
---|---|---|
committer | githubert <ikseno@googlemail.com> | 2012-09-17 00:51:12 +0200 |
commit | d5ea2b2ae8ee6d49c56a6c9b93dcf58d490dbd89 (patch) | |
tree | f0fac0059daa9557f05212841fc442cb29d3af29 /ausgezornt.go | |
parent | 0711fbc547e20b6169df0ac6da55a7f7cc757ed1 (diff) |
Zorn shall be off at night!
Diffstat (limited to 'ausgezornt.go')
-rw-r--r-- | ausgezornt.go | 62 |
1 files changed, 62 insertions, 0 deletions
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."); + } + } + } +} + |