mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Status and weather refresh on a global interval
This commit is contained in:
parent
8a258225c9
commit
69e0034871
@ -2,6 +2,7 @@ package status
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
@ -28,6 +29,7 @@ func (widget *Widget) Refresh() {
|
||||
widget.View.SetTitle(" 🦊 Status ")
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
widget.View.Clear()
|
||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom())
|
||||
}
|
||||
|
||||
@ -44,5 +46,6 @@ func (widget *Widget) addView() {
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom() string {
|
||||
return "cats and gods\ndogs and tacs"
|
||||
//return "cats and gods\ndogs and tacs"
|
||||
return fmt.Sprint(rand.Intn(100))
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package weather
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
owm "github.com/briandowns/openweathermap"
|
||||
@ -31,6 +32,7 @@ func (widget *Widget) Refresh() {
|
||||
widget.View.SetTitle(fmt.Sprintf(" %s Weather - %s ", icon(data), data.Name))
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
widget.View.Clear()
|
||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
||||
}
|
||||
|
||||
@ -53,10 +55,13 @@ func centerText(str string, width int) string {
|
||||
func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
||||
str := fmt.Sprintf("\n")
|
||||
|
||||
descs := []string{}
|
||||
for _, weather := range data.Weather {
|
||||
str = str + fmt.Sprintf(" %s\n\n", weather.Description)
|
||||
descs = append(descs, fmt.Sprintf(" %s", weather.Description))
|
||||
}
|
||||
|
||||
str = str + strings.Join(descs, ",") + "\n\n"
|
||||
|
||||
str = str + fmt.Sprintf("%10s: %4.1f° C\n\n", "Current", data.Main.Temp)
|
||||
str = str + fmt.Sprintf("%10s: %4.1f° C\n", "High", data.Main.TempMax)
|
||||
str = str + fmt.Sprintf("%10s: %4.1f° C\n", "Low", data.Main.TempMin)
|
||||
@ -76,6 +81,8 @@ func icon(data *owm.CurrentWeatherData) string {
|
||||
icon = "☀️"
|
||||
case "cloudy":
|
||||
icon = "⛅️"
|
||||
case "fog":
|
||||
icon = "🌫"
|
||||
case "heavy rain":
|
||||
icon = "💦"
|
||||
case "heavy snow":
|
||||
@ -86,6 +93,8 @@ func icon(data *owm.CurrentWeatherData) string {
|
||||
icon = "🌦"
|
||||
case "light snow":
|
||||
icon = "🌨"
|
||||
case "mist":
|
||||
icon = "🌬"
|
||||
case "moderate rain":
|
||||
icon = "🌧"
|
||||
case "moderate snow":
|
||||
|
11
wtf.go
11
wtf.go
@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
//"time"
|
||||
"time"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/bamboohr"
|
||||
@ -35,6 +35,15 @@ func main() {
|
||||
grid.AddItem(stat.View, 2, 0, 2, 3, 0, 0, false)
|
||||
grid.AddItem(weather.View, 0, 1, 1, 1, 0, 0, false)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(900 * time.Second) // 15 minutes
|
||||
stat.Refresh()
|
||||
weather.Refresh()
|
||||
app.Draw()
|
||||
}
|
||||
}()
|
||||
|
||||
if err := app.SetRoot(grid, true).Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user