1
0
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:
Chris Cummer
2019-04-14 10:04:58 -07:00
parent 73e0e18ebc
commit 27b4274d38
8 changed files with 254 additions and 62 deletions

View File

@@ -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,
)
}

View 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
}

View File

@@ -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