mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 Cryptolive extracted to new config format
This commit is contained in:
parent
73e0e18ebc
commit
27b4274d38
3
main.go
3
main.go
@ -202,7 +202,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
cfg := cmdrunner.NewSettingsFromYAML(wtf.Config)
|
||||
widget = cmdrunner.NewWidget(app, cfg)
|
||||
case "cryptolive":
|
||||
widget = cryptolive.NewWidget(app)
|
||||
cfg := cryptolive.NewSettingsFromYAML(wtf.Config)
|
||||
widget = cryptolive.NewWidget(app, cfg)
|
||||
case "datadog":
|
||||
widget = datadog.NewWidget(app)
|
||||
case "gcal":
|
||||
|
63
modules/cryptoexchanges/cryptolive/price/settings.go
Normal file
63
modules/cryptoexchanges/cryptolive/price/settings.go
Normal file
@ -0,0 +1,63 @@
|
||||
package price
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type colors struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
price string
|
||||
}
|
||||
top struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
field string
|
||||
value string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
currencies map[string]interface{}
|
||||
top map[string]interface{}
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.cryptolive")
|
||||
|
||||
currencies, _ := localConfig.Map("currencies")
|
||||
top, _ := localConfig.Map("top")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
currencies: currencies,
|
||||
top: top,
|
||||
}
|
||||
|
||||
settings.colors.from.name = localConfig.UString("colors.from.name")
|
||||
settings.colors.from.displayName = localConfig.UString("colors.from.displayName")
|
||||
|
||||
settings.colors.to.name = localConfig.UString("colors.to.name")
|
||||
settings.colors.to.price = localConfig.UString("colors.to.price")
|
||||
|
||||
settings.colors.top.from.name = localConfig.UString("colors.top.from.name")
|
||||
settings.colors.top.from.displayName = localConfig.UString("colors.top.from.displayName")
|
||||
|
||||
settings.colors.top.to.name = localConfig.UString("colors.top.to.name")
|
||||
settings.colors.top.to.field = localConfig.UString("colors.top.to.field")
|
||||
settings.colors.top.to.value = localConfig.UString("colors.top.to.value")
|
||||
|
||||
return &settings
|
||||
}
|
@ -16,6 +16,7 @@ var ok = true
|
||||
// Widget define wtf widget to register widget later
|
||||
type Widget struct {
|
||||
*list
|
||||
settings *Settings
|
||||
|
||||
Result string
|
||||
|
||||
@ -23,8 +24,10 @@ type Widget struct {
|
||||
}
|
||||
|
||||
// NewWidget Make new instance of widget
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{}
|
||||
func NewWidget(settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.setList()
|
||||
|
||||
@ -32,11 +35,9 @@ func NewWidget() *Widget {
|
||||
}
|
||||
|
||||
func (widget *Widget) setList() {
|
||||
currenciesMap, _ := wtf.Config.Map("wtf.mods.cryptolive.currencies")
|
||||
|
||||
widget.list = &list{}
|
||||
|
||||
for currency := range currenciesMap {
|
||||
for currency := range widget.settings.currencies {
|
||||
displayName, _ := wtf.Config.String("wtf.mods.cryptolive.currencies." + currency + ".displayName")
|
||||
toList := getToList(currency)
|
||||
widget.list.addItem(currency, displayName, toList)
|
||||
@ -66,16 +67,23 @@ func (widget *Widget) Refresh(wg *sync.WaitGroup) {
|
||||
|
||||
func (widget *Widget) display() {
|
||||
str := ""
|
||||
var (
|
||||
fromNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.from.name", "coral")
|
||||
fromDisplayNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.from.displayName", "grey")
|
||||
toNameColor = wtf.Config.UString("wtf.mods.cryptolive.colors.to.name", "white")
|
||||
toPriceColor = wtf.Config.UString("wtf.mods.cryptolive.colors.to.price", "green")
|
||||
)
|
||||
|
||||
for _, item := range widget.list.items {
|
||||
str += fmt.Sprintf(" [%s]%s[%s] (%s)\n", fromNameColor, item.displayName, fromDisplayNameColor, item.name)
|
||||
str += fmt.Sprintf(
|
||||
" [%s]%s[%s] (%s)\n",
|
||||
widget.settings.colors.from.name,
|
||||
item.displayName,
|
||||
widget.settings.colors.from.name,
|
||||
item.name,
|
||||
)
|
||||
for _, toItem := range item.to {
|
||||
str += fmt.Sprintf("\t[%s]%s: [%s]%f\n", toNameColor, toItem.name, toPriceColor, toItem.price)
|
||||
str += fmt.Sprintf(
|
||||
"\t[%s]%s: [%s]%f\n",
|
||||
widget.settings.colors.to.name,
|
||||
toItem.name,
|
||||
widget.settings.colors.to.price,
|
||||
toItem.price,
|
||||
)
|
||||
}
|
||||
str += "\n"
|
||||
}
|
||||
|
71
modules/cryptoexchanges/cryptolive/settings.go
Normal file
71
modules/cryptoexchanges/cryptolive/settings.go
Normal file
@ -0,0 +1,71 @@
|
||||
package cryptolive
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
"github.com/wtfutil/wtf/modules/cryptoexchanges/cryptolive/price"
|
||||
"github.com/wtfutil/wtf/modules/cryptoexchanges/cryptolive/toplist"
|
||||
)
|
||||
|
||||
type colors struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
price string
|
||||
}
|
||||
top struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
field string
|
||||
value string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
currencies map[string]interface{}
|
||||
top map[string]interface{}
|
||||
|
||||
priceSettings *price.Settings
|
||||
toplistSettings *toplist.Settings
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.cryptolive")
|
||||
|
||||
currencies, _ := localConfig.Map("currencies")
|
||||
top, _ := localConfig.Map("top")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
currencies: currencies,
|
||||
top: top,
|
||||
|
||||
priceSettings: price.NewSettingsFromYAML(ymlConfig),
|
||||
toplistSettings: toplist.NewSettingsFromYAML(ymlConfig),
|
||||
}
|
||||
|
||||
settings.colors.from.name = localConfig.UString("colors.from.name")
|
||||
settings.colors.from.displayName = localConfig.UString("colors.from.displayName")
|
||||
|
||||
settings.colors.to.name = localConfig.UString("colors.to.name")
|
||||
settings.colors.to.price = localConfig.UString("colors.to.price")
|
||||
|
||||
settings.colors.top.from.name = localConfig.UString("colors.top.from.name")
|
||||
settings.colors.top.from.displayName = localConfig.UString("colors.top.from.displayName")
|
||||
|
||||
settings.colors.top.to.name = localConfig.UString("colors.top.to.name")
|
||||
settings.colors.top.to.field = localConfig.UString("colors.top.to.field")
|
||||
settings.colors.top.to.value = localConfig.UString("colors.top.to.value")
|
||||
|
||||
return &settings
|
||||
}
|
@ -7,49 +7,54 @@ func (widget *Widget) display() {
|
||||
for _, fromCurrency := range widget.list.items {
|
||||
str += fmt.Sprintf(
|
||||
"[%s]%s [%s](%s)\n",
|
||||
widget.colors.from.displayName,
|
||||
widget.settings.colors.from.displayName,
|
||||
fromCurrency.displayName,
|
||||
widget.colors.from.name,
|
||||
widget.settings.colors.from.name,
|
||||
fromCurrency.name,
|
||||
)
|
||||
str += makeToListText(fromCurrency.to, widget.colors)
|
||||
str += widget.makeToListText(fromCurrency.to)
|
||||
}
|
||||
|
||||
widget.Result = str
|
||||
}
|
||||
|
||||
func makeToListText(toList []*tCurrency, colors textColors) string {
|
||||
func (widget *Widget) makeToListText(toList []*tCurrency) string {
|
||||
str := ""
|
||||
for _, toCurrency := range toList {
|
||||
str += makeToText(toCurrency, colors)
|
||||
str += widget.makeToText(toCurrency)
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
func makeToText(toCurrency *tCurrency, colors textColors) string {
|
||||
func (widget *Widget) makeToText(toCurrency *tCurrency) string {
|
||||
str := ""
|
||||
str += fmt.Sprintf(" [%s]%s\n", colors.to.name, toCurrency.name)
|
||||
str += fmt.Sprintf(
|
||||
" [%s]%s\n",
|
||||
widget.settings.colors.to.name,
|
||||
toCurrency.name,
|
||||
)
|
||||
|
||||
for _, info := range toCurrency.info {
|
||||
str += makeInfoText(info, colors)
|
||||
str += widget.makeInfoText(info)
|
||||
str += "\n\n"
|
||||
}
|
||||
return str
|
||||
}
|
||||
|
||||
func makeInfoText(info tInfo, colors textColors) string {
|
||||
func (widget *Widget) makeInfoText(info tInfo) string {
|
||||
return fmt.Sprintf(
|
||||
" [%s]Exchange: [%s]%s\n",
|
||||
colors.to.field,
|
||||
colors.to.value,
|
||||
widget.settings.colors.top.to.field,
|
||||
widget.settings.colors.top.to.value,
|
||||
info.exchange,
|
||||
) +
|
||||
fmt.Sprintf(
|
||||
" [%s]Volume(24h): [%s]%f-[%s]%f",
|
||||
colors.to.field,
|
||||
colors.to.value,
|
||||
widget.settings.colors.top.to.field,
|
||||
widget.settings.colors.top.to.value,
|
||||
info.volume24h,
|
||||
colors.to.value,
|
||||
widget.settings.colors.top.to.value,
|
||||
info.volume24hTo,
|
||||
)
|
||||
}
|
||||
|
63
modules/cryptoexchanges/cryptolive/toplist/settings.go
Normal file
63
modules/cryptoexchanges/cryptolive/toplist/settings.go
Normal file
@ -0,0 +1,63 @@
|
||||
package toplist
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type colors struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
price string
|
||||
}
|
||||
top struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
field string
|
||||
value string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
currencies map[string]interface{}
|
||||
top map[string]interface{}
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.cryptolive")
|
||||
|
||||
currencies, _ := localConfig.Map("currencies")
|
||||
top, _ := localConfig.Map("top")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
currencies: currencies,
|
||||
top: top,
|
||||
}
|
||||
|
||||
settings.colors.from.name = localConfig.UString("colors.from.name")
|
||||
settings.colors.from.displayName = localConfig.UString("colors.from.displayName")
|
||||
|
||||
settings.colors.to.name = localConfig.UString("colors.to.name")
|
||||
settings.colors.to.price = localConfig.UString("colors.to.price")
|
||||
|
||||
settings.colors.top.from.name = localConfig.UString("colors.top.from.name")
|
||||
settings.colors.top.from.displayName = localConfig.UString("colors.top.from.displayName")
|
||||
|
||||
settings.colors.top.to.name = localConfig.UString("colors.top.to.name")
|
||||
settings.colors.top.to.field = localConfig.UString("colors.top.to.field")
|
||||
settings.colors.top.to.value = localConfig.UString("colors.top.to.value")
|
||||
|
||||
return &settings
|
||||
}
|
@ -13,44 +13,30 @@ import (
|
||||
|
||||
var baseURL = "https://min-api.cryptocompare.com/data/top/exchanges"
|
||||
|
||||
type textColors struct {
|
||||
from struct {
|
||||
name string
|
||||
displayName string
|
||||
}
|
||||
to struct {
|
||||
name string
|
||||
field string
|
||||
value string
|
||||
}
|
||||
}
|
||||
|
||||
// Widget Toplist Widget
|
||||
type Widget struct {
|
||||
Result string
|
||||
|
||||
RefreshInterval int
|
||||
|
||||
list *cList
|
||||
|
||||
colors textColors
|
||||
list *cList
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget Make new toplist widget
|
||||
func NewWidget() *Widget {
|
||||
widget := Widget{}
|
||||
func NewWidget(settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.list = &cList{}
|
||||
widget.setList()
|
||||
widget.config()
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
func (widget *Widget) setList() {
|
||||
currenciesMap, _ := wtf.Config.Map("wtf.mods.cryptolive.top")
|
||||
|
||||
for fromCurrency := range currenciesMap {
|
||||
for fromCurrency := range widget.settings.top {
|
||||
displayName := wtf.Config.UString("wtf.mods.cryptolive.top."+fromCurrency+".displayName", "")
|
||||
limit := wtf.Config.UInt("wtf.mods.cryptolive.top."+fromCurrency+".limit", 1)
|
||||
widget.list.addItem(fromCurrency, displayName, limit, makeToList(fromCurrency, limit))
|
||||
@ -70,15 +56,6 @@ func makeToList(fCurrencyName string, limit int) (list []*tCurrency) {
|
||||
return
|
||||
}
|
||||
|
||||
func (widget *Widget) config() {
|
||||
// set colors
|
||||
widget.colors.from.name = wtf.Config.UString("wtf.mods.cryptolive.colors.top.from.name", "coral")
|
||||
widget.colors.from.displayName = wtf.Config.UString("wtf.mods.cryptolive.colors.top.from.displayName", "grey")
|
||||
widget.colors.to.name = wtf.Config.UString("wtf.mods.cryptolive.colors.top.to.name", "red")
|
||||
widget.colors.to.field = wtf.Config.UString("wtf.mods.cryptolive.colors.top.to.field", "white")
|
||||
widget.colors.to.value = wtf.Config.UString("wtf.mods.cryptolive.colors.top.to.value", "value")
|
||||
}
|
||||
|
||||
/* -------------------- Exported Functions -------------------- */
|
||||
|
||||
// Refresh & update after interval time
|
||||
|
@ -13,16 +13,20 @@ import (
|
||||
// Widget define wtf widget to register widget later
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
|
||||
priceWidget *price.Widget
|
||||
toplistWidget *toplist.Widget
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
// NewWidget Make new instance of widget
|
||||
func NewWidget(app *tview.Application) *Widget {
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(app, "CryptoLive", "cryptolive", false),
|
||||
priceWidget: price.NewWidget(),
|
||||
toplistWidget: toplist.NewWidget(),
|
||||
TextWidget: wtf.NewTextWidget(app, "CryptoLive", "cryptolive", false),
|
||||
|
||||
priceWidget: price.NewWidget(settings.priceSettings),
|
||||
toplistWidget: toplist.NewWidget(settings.toplistSettings),
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.priceWidget.RefreshInterval = widget.RefreshInterval()
|
||||
|
Loading…
x
Reference in New Issue
Block a user