From 513fca461c26cbdc6a786ef8e5c5dae232cedef8 Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Wed, 7 Feb 2024 16:58:13 -0500 Subject: [PATCH 1/3] Set the sunrise/sunset information from the api --- backends/openweathermap.org.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/backends/openweathermap.org.go b/backends/openweathermap.org.go index 4d8a9de..82a7f87 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"` } @@ -252,6 +256,14 @@ func (c *openWeatherConfig) Fetch(location string, numdays int) iface.Data { log.Fatalf("Failed to fetch weather data: %v\n", err) } 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 } From 7ac1e2262af73e7a31affe26f06d497f221fc9b9 Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Wed, 7 Feb 2024 16:58:48 -0500 Subject: [PATCH 2/3] Print the astronomy information if present --- frontends/emoji.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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) From 5850759be9d108784453c39d0045632382fdd5a6 Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Wed, 7 Feb 2024 22:02:05 -0500 Subject: [PATCH 3/3] Enable caching build environments --- .github/workflows/go.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e1a677f..0506f3d 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,8 +16,8 @@ jobs: - name: Set up Go uses: actions/setup-go@v5 with: + cache-dependency-path: './go.sum' go-version-file: './go.mod' - - name: Build run: go build -v ./...