mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
update the views
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
package finnhub
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
"github.com/wtfutil/wtf/utils"
|
||||
"os"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultFocusable = true
|
||||
defaultTitle = "Finnhub Stock Price"
|
||||
defaultTitle = "📈 Stocks Price"
|
||||
)
|
||||
|
||||
// Settings defines the configuration properties for this module
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
common *cfg.Common
|
||||
apiKey string `help:"Your finnhub API token."`
|
||||
symbols []string `help:"An array of stocks symbols (i.e. AAPL, MSFT)"`
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package finnhub
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jedib0t/go-pretty/table"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/view"
|
||||
)
|
||||
@@ -43,25 +44,20 @@ func (widget *Widget) content() (string, string, bool) {
|
||||
quotes, err := widget.Client.Getquote()
|
||||
|
||||
title := widget.CommonSettings().Title
|
||||
var str string
|
||||
t := table.NewWriter()
|
||||
t.AppendHeader(table.Row{"#", "Stock", "Current Price", "Open Price", "Change"})
|
||||
wrap := false
|
||||
if err != nil {
|
||||
wrap = true
|
||||
str = err.Error()
|
||||
} else {
|
||||
for idx, q := range quotes {
|
||||
if idx > 10 {
|
||||
break
|
||||
}
|
||||
|
||||
str += fmt.Sprintf(
|
||||
"[%d]: %s %.2f\n",
|
||||
idx,
|
||||
q.Stock,
|
||||
q.C,
|
||||
)
|
||||
t.AppendRows([]table.Row{
|
||||
{idx, q.Stock, q.C, q.O, fmt.Sprintf("%.4f", (q.C-q.O)/q.C)},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
str := fmt.Sprintf(t.Render())
|
||||
|
||||
return title, str, wrap
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user