From 8175ead867f2d478612e0a7f9d10a1522580bea3 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Tue, 4 Mar 2014 13:12:58 +0100 Subject: Weather place is now configurable --- yr_no.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) 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" -- cgit v1.2.3-70-g09d2