summary refs log tree commit diff
path: root/.config/waybar/modules
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2021-02-23 13:36:27 +0100
committerRobert Günzler <r@gnzler.io>2021-04-26 02:09:45 +0200
commit4b71908c30807c9d726e83378e04ccae28dff334 (patch)
treeab3c37125a69803ffdaba7cdcac9014c437f3215 /.config/waybar/modules
parent6cb604cdeb78b151d7e179d4f34f00101c912282 (diff)
waybar: update 2021-02-23T13:36:34Z+01:00
Diffstat (limited to '.config/waybar/modules')
-rwxr-xr-x.config/waybar/modules/covid.sh43
-rw-r--r--.config/waybar/modules/todo.go68
2 files changed, 65 insertions, 46 deletions
diff --git a/.config/waybar/modules/covid.sh b/.config/waybar/modules/covid.sh
new file mode 100755
index 0000000..b30321c
--- /dev/null
+++ b/.config/waybar/modules/covid.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+set -e
+[ -n "$DEBUG" ] && { set -x; curl_args='-v'; }
+
+# incidence = (sumCasesLast7Days / EWZ) * 100000
+lat=52.54
+lon=13.44
+fields='GEN,RS,EWZ,EWZ_BL,BL_ID,cases,cases_per_100k,cases7_per_100k,cases7_bl_per_100k,last_update,BL,IBZ'
+uri="https://services7.arcgis.com/mOBPykOjAyBO2ZKk/arcgis/rest/services/RKI_Landkreisdaten/FeatureServer/0/query?where=1%3D1&outFields=${fields}&geometry=${lon}%2C${lat}&geometryType=esriGeometryPoint&inSR=4326&spatialRel=esriSpatialRelWithin&returnGeometry=false&outSR=4326&f=json"
+
+_data=$(curl -sSL -H 'Accept: application/json' ${curl_args} ${uri} | jq -r '.features[0].attributes')
+loc=$(printf "${_data}" | jq -r '.GEN')
+incidence_f=$(printf "%.1f" $(printf "${_data}" | jq -r '.cases7_bl_per_100k'))
+incidence_i=$(printf "%.0f" "${incidence_f}")
+
+color='green'
+if [ "${incidence_i}" -eq "0" ]; then
+	color='gray'
+fi
+if [ "${incidence_i}" -gt "1" ]; then
+	color='green'
+fi
+if [ "${incidence_i}" -gt "25" ]; then
+	color='yellow'
+fi
+if [ "${incidence_i}" -gt "35" ]; then
+	color='orange'
+fi
+if [ "${incidence_i}" -gt "50" ]; then
+	color='red'
+fi
+if [ "${incidence_i}" -gt "100" ]; then
+	color='darkred'
+fi
+if [ "${incidence_i}" -gt "250" ]; then
+	color='darkdarkred'
+fi
+
+jq -nr \
+	--arg "if" "${incidence_f}" \
+	--arg "ii" "${incidence_i}" \
+	"{ text: \$if, percentage: \$ii, class: \"${color}\", alt: \"${color}\", tooltip: \"7 Tage Inzidenz für \\n${loc}\" } | @text"
diff --git a/.config/waybar/modules/todo.go b/.config/waybar/modules/todo.go
index 449f991..4f403f5 100644
--- a/.config/waybar/modules/todo.go
+++ b/.config/waybar/modules/todo.go
@@ -11,17 +11,14 @@
 package main
 
 import (
-	"bytes"
+	"bufio"
 	"encoding/json"
-	"fmt"
-	"io/ioutil"
 	"log"
 	"os"
 	"os/exec"
 	"os/signal"
 	"regexp"
 	"strings"
-	"text/scanner"
 	"time"
 
 	"github.com/fsnotify/fsnotify"
@@ -29,7 +26,7 @@ import (
 )
 
 const (
-	TODO_LINE_CHAR       rune   = '*'
+	TODO_LINE_CHAR       string = "* "
 	TODO_INACTIVE_STRING string = ""
 	TODO_LABEL_REGEX     string = `\[\[!(.*)\]\]`
 )
@@ -56,47 +53,26 @@ type todoItem struct {
 	label string
 }
 
-func readTodofile(path string) ([]todoItem, error) {
-	content, err := ioutil.ReadFile(path)
+func readTodofile2(path string) ([]todoItem, error) {
+	f, err := os.Open(path)
 	if err != nil {
-		return nil, fmt.Errorf("reading file: %v", err)
+		return nil, err
 	}
-
 	var (
-		sc        scanner.Scanner
-		validLine bool
-		todos     []todoItem
+		todos []todoItem
 	)
-	sc.Init(bytes.NewReader(content))
-	sc.Filename = path
-	sc.Whitespace ^= 1<<'\n' | 1<<' ' // don't skip newlines or spaces
-	sc.Mode ^= scanner.GoTokens
-	for tok := sc.Scan(); tok != scanner.EOF; tok = sc.Scan() {
-		switch {
-		// a valid line stats with TODO_LINE_CHAR
-		// followed by a space
-		// we strip them before appending the line array
-		case tok == TODO_LINE_CHAR && sc.Peek() == ' ':
-			validLine = true
-			_ = sc.Scan()                     // swallow the space
-			todos = append(todos, todoItem{}) // grow the array
-
-		case tok == '\n':
-			validLine = false
-			if len(todos) > 0 {
-				idx := len(todos) - 1
-				matches := labelre.FindAllStringSubmatch(todos[idx].text, -1)
-				if matches != nil && len(matches) > 0 {
-					todos[idx].label = matches[0][1]
-					todos[idx].text = strings.TrimSpace(
-						strings.Replace(todos[idx].text, matches[0][0], "", 1))
-				}
-			}
-
-		case validLine:
-			todos[len(todos)-1].text = todos[len(todos)-1].text + sc.TokenText()
+	for lr := bufio.NewScanner(f); lr.Scan(); {
+		if !strings.HasPrefix(lr.Text(), TODO_LINE_CHAR) {
+			continue
 		}
-
+		ti := todoItem{text: lr.Text()[2:]}
+		matches := labelre.FindAllStringSubmatch(ti.text, -1)
+		if matches != nil && len(matches) > 0 {
+			ti.label = matches[0][1]
+			ti.text = strings.TrimSpace(
+				strings.Replace(ti.text, matches[0][0], "", 1))
+		}
+		todos = append(todos, ti)
 	}
 	return todos, nil
 }
@@ -115,15 +91,15 @@ func update() error {
 		active = false
 	}
 	if !active {
-		return printJson(TODO_INACTIVE_STRING, "* inactive *", []string{"off"}, "todo-off", 0)
+		return printJson(TODO_INACTIVE_STRING, "* inactive *", []string{"off"}, "off", 0)
 	}
-	todos, err := readTodofile(todofile)
+	todos, err := readTodofile2(todofile)
 	if err != nil {
 		return err
 	}
 	var (
 		text       string
-		tooltip    string
+		tooltip    []string
 		extraClass string
 	)
 	for _, item := range todos {
@@ -136,9 +112,9 @@ func update() error {
 			continue
 		}
 		// render out the rest of the todos into the tooltip
-		tooltip = strings.Join([]string{tooltip, item.text}, "\n")
+		tooltip = append(tooltip, item.text)
 	}
-	return printJson(text, tooltip, []string{"on", extraClass}, "todo-on", 1)
+	return printJson(text, strings.Join(tooltip, "\n"), []string{"on", extraClass}, "on", 1)
 }
 
 var (