summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-03-04 13:12:58 +0100
committerKevin Chabowski <kevin@kch42.de>2014-03-04 13:12:58 +0100
commit8175ead867f2d478612e0a7f9d10a1522580bea3 (patch)
tree2e4349a85a1c2bce6fe78b8274cf59dad434af23
parent53edddffd1f95de0e5ff27bf555e34fa28386bcd (diff)
downloadstartpage-8175ead867f2d478612e0a7f9d10a1522580bea3.tar.gz
startpage-8175ead867f2d478612e0a7f9d10a1522580bea3.tar.bz2
startpage-8175ead867f2d478612e0a7f9d10a1522580bea3.zip
Weather place is now configurable
-rw-r--r--yr_no.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/yr_no.go b/yr_no.go
index 455d604..38ec8eb 100644
--- a/yr_no.go
+++ b/yr_no.go
@@ -1,9 +1,13 @@
package main
import (
+ "bytes"
"encoding/xml"
"fmt"
+ "io"
"net/http"
+ "os"
+ "strings"
"time"
)
@@ -57,7 +61,21 @@ type weatherdata struct {
Forecast []*Weather `xml:"forecast>tabular>time"`
}
-const place = "Germany/Schleswig-Holstein/Lübeck"
+func getPlace() string {
+ fh, err := os.Open(os.ExpandEnv("$HOME/.startpage-weather"))
+ if err != nil {
+ panic(err)
+ }
+ defer fh.Close()
+
+ buf := new(bytes.Buffer)
+ if _, err := io.Copy(buf, fh); err != nil {
+ panic(err)
+ }
+ return strings.TrimSpace(string(buf.Bytes()))
+}
+
+var place = getPlace()
func CurrentWeather() (Weather, Sun, error) {
url := "http://www.yr.no/place/" + place + "/forecast_hour_by_hour.xml"