Simon Vieille
79fe14e059
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
r "gitnet.fr/deblan/i3-blocks-go/rendering"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
type Telemetry struct {
|
|
Progress int `json:"progress"`
|
|
TempNozzle int `json:"temp_nozzle"`
|
|
TempBed int `json:"temp_bed"`
|
|
TimeEst string `json:"time_est"`
|
|
}
|
|
|
|
func openBrowser(wg *sync.WaitGroup, url string) {
|
|
defer wg.Done()
|
|
command := exec.Command("tmux", "new", "-d", "xdg-open", url)
|
|
command.Run()
|
|
}
|
|
|
|
func main() {
|
|
var wg sync.WaitGroup
|
|
|
|
argBlock := flag.String("block", "rss", "block name")
|
|
argFeed := flag.String("feed", "", "url of the feed")
|
|
argWebsite := flag.String("website", "", "website")
|
|
argEmptyColor := flag.String("empty-color", "#CCCCCC", "empty color")
|
|
argNonEmptyColor := flag.String("non-empty-color", "#B3FF6C", "when items color")
|
|
flag.Parse()
|
|
|
|
if os.Getenv("BLOCK_BUTTON") == "1" {
|
|
wg.Add(1)
|
|
go openBrowser(&wg, *argWebsite)
|
|
}
|
|
|
|
resp, err := http.Get(*argFeed)
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
body, _ := io.ReadAll(resp.Body)
|
|
content := string(body)
|
|
count := strings.Count(content, "<item") + strings.Count(content, "<entry")
|
|
label := r.FontAwesome("\uf09e")
|
|
|
|
fb := r.FB{
|
|
Foreground: *argEmptyColor,
|
|
Background: r.Color("black2"),
|
|
}
|
|
|
|
if count > 0 {
|
|
label = fmt.Sprintf("%s +%d", label, count)
|
|
fb.Foreground = *argNonEmptyColor
|
|
}
|
|
|
|
options := r.NewBlockOptions()
|
|
options.FullText = r.TextWithPadding(label, fb)
|
|
block := r.Block(*argBlock, options)
|
|
|
|
fmt.Println(block)
|
|
wg.Wait()
|
|
}
|