From db07fd6d4b2700c3980bb0881341c94c7b480095 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 28 Aug 2022 22:21:31 +0200 Subject: [PATCH] add block rss --- blocks/rss/main.go | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 blocks/rss/main.go diff --git a/blocks/rss/main.go b/blocks/rss/main.go new file mode 100644 index 0000000..b694bf4 --- /dev/null +++ b/blocks/rss/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "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 + + if os.Getenv("BLOCK_BUTTON") == "1" { + wg.Add(1) + go openBrowser(&wg, os.Args[3]) + } + + resp, err := http.Get(os.Args[2]) + + if err != nil { + return + } + + defer resp.Body.Close() + body, _ := io.ReadAll(resp.Body) + content := string(body) + count := strings.Count(content, " 0 { + label = fmt.Sprintf("%s +%d", label, count) + fb.Foreground = os.Args[5] + } + + options := r.NewBlockOptions() + options.FullText = r.TextWithPadding(label, fb) + block := r.Block(os.Args[1], options) + + fmt.Println(block) + wg.Wait() +}