Simon Vieille
eb82aba33c
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
59 lines
1.1 KiB
Go
59 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
r "gitnet.fr/deblan/i3-blocks-go/rendering"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
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
|
|
|
|
argLocation := flag.String("loc", "", "location")
|
|
argLang := flag.String("lang", "fr", "lang")
|
|
flag.Parse()
|
|
|
|
url := fmt.Sprintf("https://%s.wttr.in/%s?format=%%l+%%c+%%t+%%m", *argLang, *argLocation)
|
|
|
|
if os.Getenv("BLOCK_BUTTON") == "1" {
|
|
url2 := fmt.Sprintf("https://%s.wttr.in/%s", *argLang, *argLocation)
|
|
wg.Add(1)
|
|
go openBrowser(&wg, url2)
|
|
}
|
|
|
|
resp, err := http.Get(url)
|
|
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
body, _ := io.ReadAll(resp.Body)
|
|
content := string(body)
|
|
|
|
fb := r.FB{
|
|
Foreground: r.Color("white1"),
|
|
Background: r.Color("black2"),
|
|
}
|
|
|
|
content = strings.ReplaceAll(content, " ", " ")
|
|
options := r.NewBlockOptions()
|
|
options.FullText = r.TextWithPadding(content, fb)
|
|
block := r.Block("meteo", options)
|
|
|
|
fmt.Println(block)
|
|
wg.Wait()
|
|
}
|