summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2014-07-29 00:49:38 +0200
committerKevin Chabowski <kevin@kch42.de>2014-07-29 00:49:38 +0200
commitef9ce0a225b28a873dc7bbb55fad52da6c9ecb65 (patch)
treedebef9d092b128cee16506a46b679631e20f1c82
parent9f71270e27cd3f3442bf0be8580bfb622f3842fa (diff)
downloadstartpage-ef9ce0a225b28a873dc7bbb55fad52da6c9ecb65.tar.gz
startpage-ef9ce0a225b28a873dc7bbb55fad52da6c9ecb65.tar.bz2
startpage-ef9ce0a225b28a873dc7bbb55fad52da6c9ecb65.zip
Fixed weather icon
it's actually much simpler than I thought!
-rw-r--r--main.go4
-rw-r--r--yr_no.go49
2 files changed, 14 insertions, 39 deletions
diff --git a/main.go b/main.go
index e37670f..9db9d5a 100644
--- a/main.go
+++ b/main.go
@@ -15,7 +15,6 @@ import (
var porn EarthPorn
var weather Weather
-var sun Sun
func trylater(ch chan<- bool) {
log.Println("Will try again later...")
@@ -39,7 +38,7 @@ func earthPornUpdater(ch chan bool) {
func weatherUpdater(ch chan bool) {
for _ = range ch {
- newW, newS, err := CurrentWeather()
+ newW, err := CurrentWeather()
if err != nil {
log.Printf("Failed getting latest weather data: %s", err)
go trylater(ch)
@@ -47,7 +46,6 @@ func weatherUpdater(ch chan bool) {
}
weather = newW
- sun = newS
log.Println("New weather data")
}
}
diff --git a/yr_no.go b/yr_no.go
index bb9c747..e1b8727 100644
--- a/yr_no.go
+++ b/yr_no.go
@@ -3,7 +3,6 @@ package main
import (
"encoding/xml"
"errors"
- "fmt"
"net/http"
"time"
)
@@ -13,48 +12,26 @@ func toTime(s string) time.Time {
return t
}
+type Temperature struct {
+ Value int `xml:"value,attr"`
+ Unit string `xml:"unit,attr"`
+}
+
type Weather struct {
Temp Temperature `xml:"temperature"`
Symbol struct {
- Number int `xml:"number,attr"`
+ Var string `xml:"var,attr"`
} `xml:"symbol"`
From string `xml:"from,attr"`
URL string
Icon string
}
-func (w *Weather) prepIcon(sun Sun) {
- rise := toTime(sun.Rise)
- set := toTime(sun.Set)
- t := toTime(w.From)
-
- night := t.Before(rise) || t.After(set)
- format := "http://symbol.yr.no/grafikk/sym/b100/%02d"
- switch w.Symbol.Number {
- case 1, 2, 3, 5, 6, 7, 8, 20, 21:
- if night {
- format += "n"
- } else {
- format += "d"
- }
- }
- format += ".png"
-
- w.Icon = fmt.Sprintf(format, w.Symbol.Number)
-}
-
-type Temperature struct {
- Value int `xml:"value,attr"`
- Unit string `xml:"unit,attr"`
-}
-
-type Sun struct {
- Rise string `xml:"rise,attr"`
- Set string `xml:"set,attr"`
+func (w *Weather) prepIcon() {
+ w.Icon = "http://symbol.yr.no/grafikk/sym/b100/" + w.Symbol.Var + ".png"
}
type weatherdata struct {
- Sun Sun `xml:"sun"`
Forecast []*Weather `xml:"forecast>tabular>time"`
}
@@ -69,23 +46,23 @@ func setPlaceCmd(params []string) error {
return nil
}
-func CurrentWeather() (Weather, Sun, error) {
+func CurrentWeather() (Weather, error) {
url := "http://www.yr.no/place/" + place + "/forecast_hour_by_hour.xml"
resp, err := http.Get(url)
if err != nil {
- return Weather{}, Sun{}, err
+ return Weather{}, err
}
defer resp.Body.Close()
var wd weatherdata
dec := xml.NewDecoder(resp.Body)
if err := dec.Decode(&wd); err != nil {
- return Weather{}, Sun{}, err
+ return Weather{}, err
}
w := wd.Forecast[0]
w.URL = "http://www.yr.no/place/" + place
- w.prepIcon(wd.Sun)
+ w.prepIcon()
- return *w, wd.Sun, nil
+ return *w, nil
}