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

YAML config added. App refreshInterval as first value

This commit is contained in:
Chris Cummer 2018-04-03 17:54:52 -07:00 committed by Chris Cummer
parent 22a9f7b194
commit 39cf8c6e1c
3 changed files with 10 additions and 11 deletions

View File

@ -1,2 +1,2 @@
wtf:
refresh_interval: 1
refreshInterval: 1

View File

@ -101,27 +101,23 @@ func Fetch() (*calendar.Events, error) {
b, err := ioutil.ReadFile("./gcal/client_secret.json")
if err != nil {
//log.Fatalf("Unable to read client secret file: %v", err)
return nil, err
}
config, err := google.ConfigFromJSON(b, calendar.CalendarReadonlyScope)
if err != nil {
//log.Fatalf("Unable to parse client secret file to config: %v", err)
return nil, err
}
client := getClient(ctx, config)
srv, err := calendar.New(client)
if err != nil {
//log.Fatalf("Unable to retrieve calendar Client %v", err)
return nil, err
}
t := today().Format(time.RFC3339)
events, err := srv.Events.List("primary").ShowDeleted(false).SingleEvents(true).TimeMin(t).MaxResults(10).OrderBy("startTime").Do()
if err != nil {
//log.Fatalf("Unable to retrieve next ten of the user's events. %v", err)
return nil, err
}

15
wtf.go
View File

@ -1,7 +1,7 @@
package main
import (
"fmt"
//"fmt"
"time"
"github.com/olebedev/config"
@ -16,6 +16,8 @@ import (
"github.com/senorprogrammer/wtf/weather"
)
var Config = loadConfig()
func loadConfig() *config.Config {
cfg, err := config.ParseYamlFile("./config.yml")
if err != nil {
@ -26,7 +28,12 @@ func loadConfig() *config.Config {
}
func refresher(stat *status.Widget, app *tview.Application) {
tick := time.NewTicker(1 * time.Second)
refreshInterval, err := Config.Int("wtf.refresh_interval")
if err != nil {
refreshInterval = 1
}
tick := time.NewTicker(time.Duration(refreshInterval) * time.Second)
quit := make(chan struct{})
for {
@ -41,10 +48,6 @@ func refresher(stat *status.Widget, app *tview.Application) {
}
func main() {
cfg := loadConfig()
fmt.Printf("%v\n", cfg)
bamboo := bamboohr.NewWidget()
bamboo.Refresh()