1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Adds in Google Calendar and Weather support (hard-coded right now)

This commit is contained in:
Chris Cummer
2018-03-28 19:40:20 -07:00
committed by Chris Cummer
parent 176052c78f
commit 8946e5cf24
12 changed files with 301 additions and 27 deletions

19
weather/client.go Normal file
View File

@@ -0,0 +1,19 @@
package weather
import (
"os"
owm "github.com/briandowns/openweathermap"
)
func Fetch() *owm.CurrentWeatherData {
w, err := owm.NewCurrent("C", "EN", os.Getenv("WTF_OWM_API_KEY"))
if err != nil {
panic(err)
}
//w.CurrentByName("Toronto,ON")
w.CurrentByID(6173331)
return w
}

38
weather/widget.go Normal file
View File

@@ -0,0 +1,38 @@
package weather
import (
"bytes"
"fmt"
"text/template"
"github.com/rivo/tview"
)
const weatherTemplate = `
{{range .Weather}}{{.Description}}{{end}}
Current: {{.Main.Temp}}° C
High: {{.Main.TempMax}}° C
Low: {{.Main.TempMin}}° C
`
func Widget() tview.Primitive {
data := Fetch()
widget := tview.NewTextView()
widget.SetBorder(true)
widget.SetDynamicColors(true)
widget.SetTitle(fmt.Sprintf(" 🌤 Weather - %s ", data.Name))
//fmt.Fprintf(widget, " %s", data.Name)
var tpl bytes.Buffer
tmpl, _ := template.New("weather").Parse(weatherTemplate)
if err := tmpl.Execute(&tpl, data); err != nil {
panic(err)
}
fmt.Fprintf(widget, " %s ", tpl.String())
return widget
}