Add CGM direction arrow to Waybar

This commit is contained in:
coolneng 2023-05-24 19:07:34 +02:00
parent 87cbce4084
commit 13e76d64b6
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
2 changed files with 32 additions and 6 deletions

View File

@ -1,14 +1,33 @@
#!/bin/sh
NIGHTSCOUT_URL="https://nightscout.coolneng.duckdns.org"
CONNECTIVITY_URL="freebsd.org"
fetch_value() {
CGM_VALUE=$(curl -s -H "api-secret: $(pass api/nightscout)" -H "accept: application/json" \
"https://nightscout.coolneng.duckdns.org/api/v1/entries?count=1" |
grep -o '"sgv":[0-9]*' | cut -d ":" -f 2)
echo "$CGM_VALUE"
"$NIGHTSCOUT_URL/api/v1/entries?count=1")
GLUCOSE=$(echo "$CGM_VALUE" | grep -o '"sgv":[0-9]*' | cut -d ":" -f 2)
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() {
if nc -zw1 freebsd.org 443; then
if nc -zw1 "$CONNECTIVITY_URL" 443; then
fetch_value
else
echo "NA"
@ -16,3 +35,4 @@ check_connectivity() {
}
check_connectivity
format_output

View File

@ -80,8 +80,14 @@
"interval": 2
},
"custom/cgm-value": {
"format": "<span foreground='#88C0D0'>󱄦</span> {}",
"format": "<span foreground='#88C0D0'>󱄦</span> {}{icon} ",
"exec": "$HOME/.local/share/scripts/cgm-value",
"interval": 2
"interval": 2,
"return-type":"json",
"format-icons": {
"up": "󰁜",
"down": "󰁃",
"flat": "󰁔",
}
}
}