mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
now will load weather api key from config if not in env
This commit is contained in:
parent
7b7971d6bf
commit
f1c4644620
@ -207,6 +207,7 @@ wtf:
|
|||||||
cityids:
|
cityids:
|
||||||
- 3370352
|
- 3370352
|
||||||
- 1283240
|
- 1283240
|
||||||
|
WTF_OWM_API_KEY: [YOUR API KEY]
|
||||||
colors:
|
colors:
|
||||||
current: "lightblue"
|
current: "lightblue"
|
||||||
enabled: true
|
enabled: true
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package weather
|
package weather
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
owm "github.com/briandowns/openweathermap"
|
owm "github.com/briandowns/openweathermap"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
|
"github.com/senorprogrammer/wtf/logger"
|
||||||
"github.com/senorprogrammer/wtf/wtf"
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -34,8 +36,9 @@ type Widget struct {
|
|||||||
|
|
||||||
// NewWidget creates and returns a new instance of the weather Widget.
|
// NewWidget creates and returns a new instance of the weather Widget.
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||||
|
configKey := "weather"
|
||||||
widget := Widget{
|
widget := Widget{
|
||||||
TextWidget: wtf.NewTextWidget(" Weather ", "weather", true),
|
TextWidget: wtf.NewTextWidget(" Weather ", configKey, true),
|
||||||
|
|
||||||
app: app,
|
app: app,
|
||||||
pages: pages,
|
pages: pages,
|
||||||
@ -44,6 +47,11 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
|||||||
Idx: 0,
|
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)
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
|
|
||||||
return &widget
|
return &widget
|
||||||
|
Loading…
x
Reference in New Issue
Block a user