breto

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

commit ac1ca6240975a35c906132cf5a2213c74d5435b0
parent c86c4537dc85d98882234da7e15fea5f585fe048
Author: Jaron Swab <jrswab@gmail.com>
Date:   Wed,  3 Jul 2019 20:36:27 -0400

Merge pull request #2 from jrswab/wttrFix

Changed wttr data check.
Diffstat:
MCHANGELOG.md | 4++++
Mblocks/wttr.go | 22+++++++++++++---------
2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.8.1] - July 3, 2019 +## Changed +- Wttr from checking for server error to checking for desired output. + ## [0.8.0] - July 2, 2019 ### Added - Battery percentage for laptops diff --git a/blocks/wttr.go b/blocks/wttr.go @@ -11,10 +11,10 @@ import ( ) // Wttr gets the weather of the computer's general location. -// Specify city or area code: "wttr.in/~15222" or "wttr.in/~Pittsuburgh" +// Specify city or area code: "wttr.in/~15222" or "wttr.in/~Pittsburgh" func Wttr(cWttr chan string, eWttr chan error) { var passed, hour float64 - var data string + var data, weather string start := time.Now() // to determine seconds passed ticker := time.NewTicker(time.Second) @@ -31,14 +31,18 @@ func Wttr(cWttr chan string, eWttr chan error) { } bodyData, _ := ioutil.ReadAll(resp.Body) - if strings.Contains(string(bodyData), "error") { // wttr.in displays a webpage on server error - eWttr <- errors.New("wttr.in overloaded") // display this on wttr.in server error - } - // convert responce to string for go channel - data = string(bodyData) - weather := fmt.Sprintf("%s |", strings.TrimSpace(data)) resp.Body.Close() - cWttr <- weather + data = string(bodyData) + + // wttr.in sends an html string during the server error. + // Several attempts to catch the exact error proved difficult + // so now we catch the correct outupt instead. + if strings.Contains(data, "+") || strings.Contains(data, "-") { + weather = fmt.Sprintf("%s |", strings.TrimSpace(data)) + cWttr <- weather + } else { + eWttr <- errors.New("wttr.in overloaded") + } } } }