Skip to content

Commit

Permalink
now will load weather api key from config if not in env
Browse files Browse the repository at this point in the history
  • Loading branch information
BillKeenan authored and Chris Cummer committed Jul 12, 2018
1 parent 7b7971d commit f1c4644
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions _sample_configs/complex_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ wtf:
cityids:
- 3370352
- 1283240
WTF_OWM_API_KEY: [YOUR API KEY]
colors:
current: "lightblue"
enabled: true
Expand Down
10 changes: 9 additions & 1 deletion weatherservices/weather/widget.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit f1c4644

Please sign in to comment.