summaryrefslogtreecommitdiff
path: root/yr_no.go
diff options
context:
space:
mode:
Diffstat (limited to 'yr_no.go')
-rw-r--r--yr_no.go24
1 files changed, 8 insertions, 16 deletions
diff --git a/yr_no.go b/yr_no.go
index 38ec8eb..bb9c747 100644
--- a/yr_no.go
+++ b/yr_no.go
@@ -1,13 +1,10 @@
package main
import (
- "bytes"
"encoding/xml"
+ "errors"
"fmt"
- "io"
"net/http"
- "os"
- "strings"
"time"
)
@@ -61,21 +58,16 @@ type weatherdata struct {
Forecast []*Weather `xml:"forecast>tabular>time"`
}
-func getPlace() string {
- fh, err := os.Open(os.ExpandEnv("$HOME/.startpage-weather"))
- if err != nil {
- panic(err)
- }
- defer fh.Close()
+var place = ""
- buf := new(bytes.Buffer)
- if _, err := io.Copy(buf, fh); err != nil {
- panic(err)
+func setPlaceCmd(params []string) error {
+ if len(params) != 1 {
+ return errors.New("set-weather-place needs one parameter")
}
- return strings.TrimSpace(string(buf.Bytes()))
-}
-var place = getPlace()
+ place = params[0]
+ return nil
+}
func CurrentWeather() (Weather, Sun, error) {
url := "http://www.yr.no/place/" + place + "/forecast_hour_by_hour.xml"