From dd4899a07ce239d9c4110f7227f8c90ef785cbb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miha=20Frange=C5=BE?= Date: Mon, 5 Oct 2020 11:08:30 +0200 Subject: [PATCH] UptimeRobot: improve uptime formatting --- modules/uptimerobot/widget.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/modules/uptimerobot/widget.go b/modules/uptimerobot/widget.go index ec8cc96d..1827a1e3 100644 --- a/modules/uptimerobot/widget.go +++ b/modules/uptimerobot/widget.go @@ -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