Last active
April 20, 2024 02:28
-
-
Save acron0/56f2acba7b5b83c50562dea491e65970 to your computer and use it in GitHub Desktop.
i3status widget for displaying my BG mmol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# 2017-11-20T09:57:46.101+0000 1511171866101 65 Flat xDrip-DexcomG5 | |
LINE=$(curl "https://acron-nightscout.herokuapp.com/api/v1/entries" 2> /dev/null | head -n1 ) | |
TIME_THEN=$(echo $LINE | awk '{ print $2 }' | cut -c -10) | |
TIME_NOW=$(date +%s) | |
MMOL=$(echo $LINE | awk '{ print $3 }') | |
ARROW=$(echo $LINE | awk '{ print $4 }') | |
MINS_SINCE=$(echo "($TIME_NOW - ${TIME_THEN:-0}) / 60" | bc | xargs printf "%sm ago") | |
case $ARROW in | |
Flat) ARROW_SYM="\\u2192" | |
;; | |
SingleUp) ARROW_SYM="\\u2191" | |
;; | |
SingleDown) ARROW_SYM="\\u2193" | |
;; | |
FortyFiveUp) ARROW_SYM="\\u2197" | |
;; | |
FortyFiveDown) ARROW_SYM="\\u2198" | |
;; | |
DoubleUp) ARROW_SYM="\\u2191\\u2191" | |
;; | |
DoubleDown) ARROW_SYM="\\u2193\\u2193" | |
;; | |
*) ARROW_SYM="????" | |
;; | |
esac | |
LEVEL=$(echo "scale=2; $MMOL.0 / 18.0" | bc) | |
LEVEL_NO_DEC=$(echo "$MMOL.0 / 18" | bc) | |
# full text | |
printf "$LEVEL mmol$ARROW_SYM ($MINS_SINCE)\n" | |
# short text | |
printf "$LEVEL mmol$ARROW_SYM\n" | |
# colour? | |
if [[ $LEVEL_NO_DEC -lt 4 ]] | |
then | |
echo "#ff0000" | |
elif [[ $LEVEL_NO_DEC -gt 10 ]] | |
then | |
echo "#ffff00" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment