1
0
mirror of https://github.com/taigrr/wtf synced 2026-03-26 19:02:18 -07:00

Implemented a module that shows exchange rates from exchangeratesapi.io

This commit is contained in:
Toon Schoenmakers
2019-11-12 18:06:45 +01:00
parent f873baea7f
commit 244a86cb7e
4 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
// Package exchangerates
package exchangerates
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
const (
defaultFocusable = false
defaultTitle = "Exchange rates"
)
// Settings defines the configuration properties for this module
type Settings struct {
common *cfg.Common
rates map[string][]string `help:"Defines what currency rates we want to know about`
}
// NewSettingsFromYAML creates a new settings instance from a YAML config block
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
rates: map[string][]string{},
}
raw := ymlConfig.UMap("rates", map[string]interface{}{})
for key, value := range raw {
settings.rates[key] = []string{}
switch value.(type) {
case string:
settings.rates[key] = []string{value.(string)}
case []interface{}:
for _, currency := range value.([]interface{}) {
str, ok := currency.(string)
if ok {
settings.rates[key] = append(settings.rates[key], str)
}
}
}
}
return &settings
}