add block rss

This commit is contained in:
Simon Vieille 2022-08-28 22:21:31 +02:00
parent 9df1465dce
commit db07fd6d4b
Signed by: deblan
GPG Key ID: 579388D585F70417
1 changed files with 63 additions and 0 deletions

63
blocks/rss/main.go Normal file
View File

@ -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, "<item") + strings.Count(content, "<entry")
label := "<span font='FontAwesome'>\uf09e</span>"
fb := r.FB{
Foreground: os.Args[4],
Background: r.Color("black2"),
}
if count > 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()
}