Add CGM direction arrow to Waybar

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

View File

@ -1,18 +1,38 @@
#!/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"
echo "{\"text\": \"NA\"}"
fi
}
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": "󰁔",
}
}
}