Add CGM direction arrow to Waybar
This commit is contained in:
parent
87cbce4084
commit
bcec83476c
|
@ -1,18 +1,38 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
NIGHTSCOUT_URL="https://nightscout.coolneng.duckdns.org"
|
||||||
|
CONNECTIVITY_URL="freebsd.org"
|
||||||
|
|
||||||
fetch_value() {
|
fetch_value() {
|
||||||
CGM_VALUE=$(curl -s -H "api-secret: $(pass api/nightscout)" -H "accept: application/json" \
|
CGM_VALUE=$(curl -s -H "api-secret: $(pass api/nightscout)" -H "accept: application/json" \
|
||||||
"https://nightscout.coolneng.duckdns.org/api/v1/entries?count=1" |
|
"$NIGHTSCOUT_URL/api/v1/entries?count=1")
|
||||||
grep -o '"sgv":[0-9]*' | cut -d ":" -f 2)
|
GLUCOSE=$(echo "$CGM_VALUE" | grep -o '"sgv":[0-9]*' | cut -d ":" -f 2)
|
||||||
echo "$CGM_VALUE"
|
DIRECTION=$(
|
||||||
|
echo "$CGM_VALUE" | grep -o '"direction":"[a-zA-Z]*"' | cut -d ":" -f 2 | tr -d \"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
format_output() {
|
||||||
|
case "$DIRECTION" in
|
||||||
|
*"Up"*)
|
||||||
|
printf "{\"text\": \"%s\",\"alt\": \"up\"}" "$GLUCOSE"
|
||||||
|
;;
|
||||||
|
*"Down"*)
|
||||||
|
printf "{\"text\": \"%s\",\"alt\": \"down\"}" "$GLUCOSE"
|
||||||
|
;;
|
||||||
|
"Flat")
|
||||||
|
printf "{\"text\": \"%s\",\"alt\": \"flat\"}" "$GLUCOSE"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
check_connectivity() {
|
check_connectivity() {
|
||||||
if nc -zw1 freebsd.org 443; then
|
if nc -zw1 "$CONNECTIVITY_URL" 443; then
|
||||||
fetch_value
|
fetch_value
|
||||||
else
|
else
|
||||||
echo "NA"
|
echo "{\"text\": \"NA\"}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
check_connectivity
|
check_connectivity
|
||||||
|
format_output
|
||||||
|
|
|
@ -80,8 +80,14 @@
|
||||||
"interval": 2
|
"interval": 2
|
||||||
},
|
},
|
||||||
"custom/cgm-value": {
|
"custom/cgm-value": {
|
||||||
"format": "<span foreground='#88C0D0'></span> {}",
|
"format": "<span foreground='#88C0D0'></span> {}{icon} ",
|
||||||
"exec": "$HOME/.local/share/scripts/cgm-value",
|
"exec": "$HOME/.local/share/scripts/cgm-value",
|
||||||
"interval": 2
|
"interval": 2,
|
||||||
|
"return-type":"json",
|
||||||
|
"format-icons": {
|
||||||
|
"up": "",
|
||||||
|
"down": "",
|
||||||
|
"flat": "",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue