From 4b9c42844bb42336a03313d21518e5d738dc75a0 Mon Sep 17 00:00:00 2001 From: Bill Keenan Date: Fri, 29 Jun 2018 09:20:44 -0400 Subject: [PATCH] now will load weather api key from config if not in env --- _sample_configs/complex_config.yml | 1 + weatherservices/weather/widget.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/_sample_configs/complex_config.yml b/_sample_configs/complex_config.yml index 5983683e..69ae0afb 100644 --- a/_sample_configs/complex_config.yml +++ b/_sample_configs/complex_config.yml @@ -207,6 +207,7 @@ wtf: cityids: - 3370352 - 1283240 + WTF_OWM_API_KEY: [YOUR API KEY] colors: current: "lightblue" enabled: true diff --git a/weatherservices/weather/widget.go b/weatherservices/weather/widget.go index 86208480..46dea7f9 100644 --- a/weatherservices/weather/widget.go +++ b/weatherservices/weather/widget.go @@ -1,11 +1,13 @@ package weather import ( + "fmt" "os" owm "github.com/briandowns/openweathermap" "github.com/gdamore/tcell" "github.com/rivo/tview" + "github.com/senorprogrammer/wtf/logger" "github.com/senorprogrammer/wtf/wtf" ) @@ -34,8 +36,9 @@ type Widget struct { // NewWidget creates and returns a new instance of the weather Widget. func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { + configKey := "weather" widget := Widget{ - TextWidget: wtf.NewTextWidget(" Weather ", "weather", true), + TextWidget: wtf.NewTextWidget(" Weather ", configKey, true), app: app, pages: pages, @@ -44,6 +47,11 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget { Idx: 0, } + if widget.APIKey == "" { + logger.Log("loading weather WTF_OWM_API_KEY key from config") + widget.APIKey = wtf.Config.UString(fmt.Sprintf("wtf.mods.%s.WTF_OWM_API_KEY", configKey), "") + } + widget.View.SetInputCapture(widget.keyboardIntercept) return &widget