diff --git a/backends/openweathermap.org.go b/backends/openweathermap.org.go index 2ca55db..1eae102 100644 --- a/backends/openweathermap.org.go +++ b/backends/openweathermap.org.go @@ -24,6 +24,10 @@ type openWeatherResponse struct { City struct { Name string `json:"name"` Country string `json:"country"` + TimeZone int64 `json: "timezone"` + // sunrise/sunset are once per call + SunRise int64 `json: "sunrise"` + SunSet int64 `json: "sunset"` } `json:"city"` List []dataBlock `json:"list"` } @@ -31,9 +35,9 @@ type openWeatherResponse struct { type dataBlock struct { Dt int64 `json:"dt"` Main struct { - TempMin float32 `json:"temp_min"` - TempMax float32 `json:"temp_max"` - Humidity int `json:"humidity"` + TempC float32 `json:"temp"` + FeelsLikeC float32 `json:"feels_like"` + Humidity int `json:"humidity"` } `json:"main"` Weather []struct { @@ -201,8 +205,8 @@ func (c *openWeatherConfig) parseCond(dataInfo dataBlock) (iface.Cond, error) { ret.Code = iface.CodeUnknown ret.Desc = dataInfo.Weather[0].Description ret.Humidity = &(dataInfo.Main.Humidity) - ret.TempC = &(dataInfo.Main.TempMin) - ret.FeelsLikeC = &(dataInfo.Main.TempMax) + ret.TempC = &(dataInfo.Main.TempC) + ret.FeelsLikeC = &(dataInfo.Main.FeelsLikeC) if &dataInfo.Wind.Deg != nil { p := int(dataInfo.Wind.Deg) ret.WinddirDegree = &p @@ -256,6 +260,14 @@ func (c *openWeatherConfig) Fetch(location string, numdays int) iface.Data { return ret } ret.Forecast = c.parseDaily(resp.List, numdays) + + // add in the sunrise/sunset information to the first day + // these maybe should deal with resp.City.TimeZone + if len(ret.Forecast) > 0 { + ret.Forecast[0].Astronomy.Sunrise = time.Unix(resp.City.SunRise, 0) + ret.Forecast[0].Astronomy.Sunset = time.Unix(resp.City.SunSet, 0) + } + return ret } diff --git a/frontends/emoji.go b/frontends/emoji.go index ca49b0e..6d93b5f 100644 --- a/frontends/emoji.go +++ b/frontends/emoji.go @@ -93,6 +93,23 @@ func (c *emojiConfig) formatCond(cur []string, cond iface.Cond, current bool) (r return } +func (c *emojiConfig) printAstro(astro iface.Astro) { + // print sun astronomy data if present + if astro.Sunrise != astro.Sunset { + // half the distance between sunrise and sunset + noon_distance := time.Duration(int64(float32(astro.Sunset.UnixNano() - astro.Sunrise.UnixNano()) * 0.5)) + // time for solar noon + noon := astro.Sunrise.Add(noon_distance) + + // the actual print statement + fmt.Printf("🌞 rise↗ %s noon↑ %s set↘ %s\n", astro.Sunrise.Format(time.Kitchen), noon.Format(time.Kitchen), astro.Sunset.Format(time.Kitchen)) + } + // print moon astronomy data if present + if astro.Moonrise != astro.Moonset { + fmt.Printf("🌚 rise↗ %s set↘ %s\n", astro.Moonrise.Format(time.Kitchen), astro.Moonset) + } +} + func (c *emojiConfig) printDay(day iface.Day) (ret []string) { desiredTimesOfDay := []time.Duration{ 8 * time.Hour, @@ -105,6 +122,8 @@ func (c *emojiConfig) printDay(day iface.Day) (ret []string) { ret[i] = "│" } + c.printAstro(day.Astronomy) + // save our selected elements from day.Slots in this array cols := make([]iface.Cond, len(desiredTimesOfDay)) // find hourly data which fits the desired times of day best @@ -157,6 +176,7 @@ func (c *emojiConfig) Render(r iface.Data, unitSystem iface.UnitSystem) { if r.Forecast == nil { log.Fatal("No detailed weather forecast available.") } + fmt.Printf("\n") for _, d := range r.Forecast { for _, val := range c.printDay(d) { fmt.Fprintln(stdout, val)