Skip to content

Instantly share code, notes, and snippets.

@cympfh
Created February 23, 2019 08:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cympfh/b239cc550b10b12693632a5d6a715df1 to your computer and use it in GitHub Desktop.
Save cympfh/b239cc550b10b12693632a5d6a715df1 to your computer and use it in GitHub Desktop.
#!/bin/bash
URL=http://s.cympfh.cc/cympfh/sleep
OUT=./neoki.png
last_status=NONE
datfile=$(mktemp)
curl -s $URL | while read t status; do
date_ymd=$(date -d "$t" "+%Y%m%d")
date_hm=$(date -d "$t" "+%H%M")
action=
if [ "$status" == "good night" -a "$status" != "$last_status" ]; then
action=ne
elif [ "$status" == "good morning" -a "$status" != "$last_status" ]; then
action=oki
fi
if [ ! -z "$action" ]; then
echo "$date_ymd $date_hm $action"
fi
last_status=$status
done > "$datfile"
gnuplot <<EOM
set terminal pngcairo size 1600,900
set output '$OUT'
set xdata time
set ydata time
xformat = "%Y%m%d"
yformat = "%H%M"
set format x "%m/%d"
set format y "%H:%M"
# ne/oki lines
set style line 1 lc rgb '#addddd' lt 1 lw 5 ps 4 pt 2
set style line 2 lc rgb '#ddadad' lt 1 lw 5 ps 4 pt 6
# tics
set style line 11 lc rgb '#808080' lt 1 lw 3
set border 0 back ls 11
set tics out nomirror
# grid
set style line 12 lc rgb '#808080' lt 0 lw 1
set grid back ls 12
set title 'neoki'
set yrange [:] reverse
plot '< grep ne $datfile' u (timecolumn(1, xformat)):(timecolumn(2, yformat)) w lp title 'ne' ls 1 ,\
'< grep oki $datfile' u (timecolumn(1, xformat)):(timecolumn(2, yformat)) w lp title 'oki' ls 2
EOM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment