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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
@ -28,6 +29,7 @@ func (widget *Widget) Refresh() {
|
|||||||
widget.View.SetTitle(" π¦ Status ")
|
widget.View.SetTitle(" π¦ Status ")
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
|
|
||||||
|
widget.View.Clear()
|
||||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom())
|
fmt.Fprintf(widget.View, "%s", widget.contentFrom())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,5 +46,6 @@ func (widget *Widget) addView() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) contentFrom() string {
|
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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
owm "github.com/briandowns/openweathermap"
|
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.View.SetTitle(fmt.Sprintf(" %s Weather - %s ", icon(data), data.Name))
|
||||||
widget.RefreshedAt = time.Now()
|
widget.RefreshedAt = time.Now()
|
||||||
|
|
||||||
|
widget.View.Clear()
|
||||||
fmt.Fprintf(widget.View, "%s", widget.contentFrom(data))
|
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 {
|
func (widget *Widget) contentFrom(data *owm.CurrentWeatherData) string {
|
||||||
str := fmt.Sprintf("\n")
|
str := fmt.Sprintf("\n")
|
||||||
|
|
||||||
|
descs := []string{}
|
||||||
for _, weather := range data.Weather {
|
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\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", "High", data.Main.TempMax)
|
||||||
str = str + fmt.Sprintf("%10s: %4.1fΒ° C\n", "Low", data.Main.TempMin)
|
str = str + fmt.Sprintf("%10s: %4.1fΒ° C\n", "Low", data.Main.TempMin)
|
||||||
@ -76,6 +81,8 @@ func icon(data *owm.CurrentWeatherData) string {
|
|||||||
icon = "βοΈ"
|
icon = "βοΈ"
|
||||||
case "cloudy":
|
case "cloudy":
|
||||||
icon = "β
οΈ"
|
icon = "β
οΈ"
|
||||||
|
case "fog":
|
||||||
|
icon = "π«"
|
||||||
case "heavy rain":
|
case "heavy rain":
|
||||||
icon = "π¦"
|
icon = "π¦"
|
||||||
case "heavy snow":
|
case "heavy snow":
|
||||||
@ -86,6 +93,8 @@ func icon(data *owm.CurrentWeatherData) string {
|
|||||||
icon = "π¦"
|
icon = "π¦"
|
||||||
case "light snow":
|
case "light snow":
|
||||||
icon = "π¨"
|
icon = "π¨"
|
||||||
|
case "mist":
|
||||||
|
icon = "π¬"
|
||||||
case "moderate rain":
|
case "moderate rain":
|
||||||
icon = "π§"
|
icon = "π§"
|
||||||
case "moderate snow":
|
case "moderate snow":
|
||||||
|
11
wtf.go
11
wtf.go
@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
//"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/senorprogrammer/wtf/bamboohr"
|
"github.com/senorprogrammer/wtf/bamboohr"
|
||||||
@ -35,6 +35,15 @@ func main() {
|
|||||||
grid.AddItem(stat.View, 2, 0, 2, 3, 0, 0, false)
|
grid.AddItem(stat.View, 2, 0, 2, 3, 0, 0, false)
|
||||||
grid.AddItem(weather.View, 0, 1, 1, 1, 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 {
|
if err := app.SetRoot(grid, true).Run(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Loadingβ¦
x
Reference in New Issue
Block a user