1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

UptimeRobot: improve uptime formatting

This commit is contained in:
Miha Frangež 2020-10-05 11:08:30 +02:00 committed by Chris Cummer
parent 6908e744e1
commit dd4899a07c

View File

@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"strings"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/view"
@ -103,13 +104,28 @@ func (widget *Widget) contentFrom(monitors []Monitor) string {
`,
prefix,
monitor.Name,
monitor.Uptime,
formatUptimes(monitor.Uptime),
)
}
return str
}
func formatUptimes(str string) string {
splits := strings.Split(str, "-")
str = ""
for i, s := range splits {
if i != 0 {
str += "|"
}
s = s[:5]
s = strings.TrimRight(s, "0")
s = strings.TrimRight(s, ".") + "%"
str += s
}
return str
}
type Monitor struct {
Name string `json:"friendly_name"`
// Monitor state, see: https://uptimerobot.com/api/#parameters