Author: Adam Evyčędo <git@apiote.xyz>
fix water syncing
.config/sh/functions | 13 ++++++++----- .gitignore | 1 +
diff --git a/.config/sh/functions b/.config/sh/functions index 6458e3ef4638dfc5c9956949befb6aa96fa6958c..3c84010f5fc59857df08865e1071e4bcba696c4a 100644 --- a/.config/sh/functions +++ b/.config/sh/functions @@ -1284,12 +1284,14 @@ drunk() { waterInit + . ~/.config/sh/waterToken + if [ "$1" = 'sync' ] then meID=$(sqlite3 "$HOME/.local/state/water/water.db" -noheader "select device_id from devices where device_type = 'me'" 2>/dev/null) - worldView=$(sqlite3 "$HOME/.local/state/water/water.db" -noheader "select 'h:' || device_id || ':' || max(clock) group by device_id from intakes" 2>/dev/null) - world=$(curl -XPUT https://monitoring.apiote.xyz/life -H"Authorization: $lifeToken" -d "$worldView") + worldView=$(sqlite3 "$HOME/.local/state/water/water.db" -noheader "select 'h:' || device_id || ':' || max(clock) from intakes group by device_id" 2>/dev/null) + world=$(curl -s -XPUT https://monitoring.apiote.xyz/life -H"Authorization: $lifeToken" -d "$worldView") intakeUpdates="" for line in $world @@ -1298,8 +1300,8 @@ case "$line" in w*) deviceID=$(echo "$line" | cut -d ':' -f 2) clock=$(echo "$line" | cut -d ':' -f 3) - intakes=$(sqlite3 "$HOME/.local/state/water/water.db" -noheader "select 'u:' || device_id || ':' || clock || ':' || date || 'T' || time || ':' || amount || ':' || drink from intakes where device_id = '$deviceID' and clock >= $clock" 2>/dev/null) - intakeUpdates="${intakeUpdates}${intakes}" # TODO with \n ? + intakes="$(sqlite3 "$HOME/.local/state/water/water.db" -noheader -list "select 'u:' || device_id || ':' || clock || ':' || date || 'T' || time || ':' || amount || ':' || drink || char(10) from intakes where device_id = '$deviceID' and clock >= $clock" 2>/dev/null)" + intakeUpdates="${intakeUpdates} ${intakes}" ;; u*) deviceID=$(echo "$line" | cut -d ':' -f 2) @@ -1315,7 +1317,8 @@ ;; esac done - curl -XPUT https://monitoring.apiote.xyz/life -H"Authorization: $lifeToken" -d "$intakeUpdates" + updateLines=$(echo $intakeUpdates | sed 's/ /\n/g') + curl -s -XPUT https://monitoring.apiote.xyz/life -H"Authorization: $lifeToken" -d "$updateLines" exit fi diff --git a/.gitignore b/.gitignore index 091c2c670850874bc12b148d08ad96ee72fc9a1d..82bf1c00c05bb034d62ed929794546a1b1814c70 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ /.config/pulse /.config/qView /.config/qalculate/qalc.history /.config/qutebrowser +/.config/sh/waterToken /.config/subtitleeditor /.config/syncthing /.config/todoman/__pycache__/