-
Notifications
You must be signed in to change notification settings - Fork 2
/
query-last-sensors
executable file
·57 lines (51 loc) · 1.34 KB
/
query-last-sensors
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
#SECRET="MyAPIsecret"
#SERVER="MyNSinstance"
#PORT=4711
. .settings
SECRETSHA1=`echo -n ${SECRET} | sha1sum - | cut -c1-40`
WHAT="${1:-Change}"
mkdir -p data
echo querying last sensors ...
LANG=C \
curl \
-s \
-H "API-SECRET: ${SECRETSHA1}" \
-H 'Accept: */*' \
-H 'Content-Type: application/json' \
"https://${SERVER}:${PORT}/api/v1/treatments.json?count=10&x=`date +%s`&find\[created_at\]\[\$gte\]=2022-07-01&find\[eventType\]=/Sensor+${WHAT}/" \
| sed -e 's~},{~}%{~g' \
-e 's~\[~[%~' -e 's~\]~%]~' \
| sed -e 's~,"carbs":null~~g' \
| sed -e 's~,"insulin":null~~g' \
| sed -e 's~,"xdatex":[^,}]*~~g' \
| sed -e 's~,"timestamp":[^,}]*~~g' \
| sed -e 's~,"xcreated_atx":[^,}]*~~g' \
| sed -e 's~,"uuid":[^,}]*~~g' \
| sed -e 's~,"sysTime":[^,}]*~~g' \
| sed -e 's~,"utcOffset":[^,}]*~~g' \
| sed -e 's~,"enteredBy":[^,}]*~~g' \
| tr '%' '\012'
# do not process further
exit
echo LINE ${line} >&2
case "${line}" in
*"\"date\":"*)
echo DATE >&2
echo "${line}" \
| sed -e 's~.*"date":\([0-9]*\)[^0-9].*~\1~' -e 's~null~0~'
;;
*"\"timestamp\":"*)
echo TIMESTAMP >&2
echo "${line}" \
| sed -e 's~.*"timestamp":\([0-9]*\)[^0-9].*~\1~' -e 's~null~0~'
;;
*)
echo NO MATCH >&2
;;
esac \
| tee /dev/stderr \
> data/last-sensor.time
echo ""
# FIXME: handle empty result
exit