This commit is contained in:
parent
251a5a11e3
commit
039bb2c2b1
14
README.md
14
README.md
|
@ -55,7 +55,7 @@ interval=1000
|
|||
|
||||
### Date
|
||||
|
||||
Show the time using given format.
|
||||
Show the time using the given format.
|
||||
|
||||
```
|
||||
[time]
|
||||
|
@ -83,6 +83,18 @@ markup=pango
|
|||
interval=30
|
||||
```
|
||||
|
||||
### Weather
|
||||
|
||||
Show the weather of the given location ([https://fr.wttr.in/](https://fr.wttr.in/)).
|
||||
|
||||
```
|
||||
[weather]
|
||||
command=/path/to/weather -loc=Paris
|
||||
format=json
|
||||
markup=pango
|
||||
interval=1800
|
||||
```
|
||||
|
||||
### IP
|
||||
|
||||
Show the IP of the given iface.
|
||||
|
|
56
blocks/weather/main.go
Normal file
56
blocks/weather/main.go
Normal file
|
@ -0,0 +1,56 @@
|
|||
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")
|
||||
flag.Parse()
|
||||
|
||||
url := fmt.Sprintf("https://fr.wttr.in/%s?format=%%l+%%c+%%t+%%m", *argLocation)
|
||||
|
||||
if os.Getenv("BLOCK_BUTTON") == "1" {
|
||||
wg.Add(1)
|
||||
go openBrowser(&wg, url)
|
||||
}
|
||||
|
||||
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()
|
||||
}
|
Loading…
Reference in a new issue