breto

A status bar written in Go.
Log | Files | Refs | README | LICENSE

commit fce847a73ddb4d75ad4a9489700ec1d5d9880d1f
parent bdda7652bbcb32180331416619c6f52de2fc7606
Author: J. R. Swab <jrswab@protonmail.com>
Date:   Mon, 27 May 2019 14:44:46 +0000

Merge branch 'weatherPointer' into 'master'

Now passing the memory address of wttr instead of the data itself

See merge request jrswab/dwm-status!5
Diffstat:
Mlibs/wttr/wttr.go | 8+++++---
Mmain.go | 11++++++-----
2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/libs/wttr/wttr.go b/libs/wttr/wttr.go @@ -6,15 +6,17 @@ import ( "strings" ) -func Local() string { +func Local() *string { // for more wttr options see https://wttr.in/:help resp, err := http.Get("https://wttr.in/?format=%t+%w") // get temp and wind direction/speed if err != nil { - return err.Error() + errMessage := "wttr connection issue" + return &errMessage } defer resp.Body.Close() // close http request // convert responce to string for return bodyData, _ := ioutil.ReadAll(resp.Body) - return strings.TrimSpace(string(bodyData)) + weather := strings.TrimSpace(string(bodyData)) + return &weather } diff --git a/main.go b/main.go @@ -1,9 +1,9 @@ package main import ( + "fmt" //"os/exec" "gitlab.com/jrswab/dwm-status/libs/ram" "gitlab.com/jrswab/dwm-status/libs/wttr" - "os/exec" "strings" "time" ) @@ -11,7 +11,7 @@ import ( func main() { // initial run var i uint16 = 0 - weather := wttr.Local() + weather := strings.TrimSpace(string(*wttr.Local())) ramFree := ram.Free() for i < 3700 { @@ -20,7 +20,7 @@ func main() { // time delayed retrievals: // get weather once per hour if i == 3600 { - weather = wttr.Local() + weather = strings.TrimSpace(string(*wttr.Local())) } // get free Ram every 3 seconds if i%3 == 0 { @@ -38,8 +38,9 @@ func main() { // concatinate all strings to one line for output status := strings.Join(cat, " ") - cmd := exec.Command("xsetroot", "-name", status) - cmd.Run() + //cmd := exec.Command("xsetroot", "-name", status) + //cmd.Run() + fmt.Println(status) time.Sleep(1 * time.Second)