-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquery-last-sgv
executable file
·37 lines (34 loc) · 1.07 KB
/
query-last-sgv
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
#!/bin/bash
#SECRET="MyAPIsecret"
#SERVER="MyNSinstance"
#PORT=4711
. .settings
SECRETSHA1=`echo -n ${SECRET} | sha1sum - | cut -c1-40`
mkdir -p data
echo querying last sgv ...
echo ... for non-scan records
LANG=C \
curl \
-s \
-H "API-SECRET: ${SECRETSHA1}" \
-H 'Accept: */*' \
-H 'Content-Type: application/json' \
"https://${SERVER}:${PORT}/api/v1/entries.json?count=1&x=`date +%s`&find\[dateString\]\[\$gte\]=2020-01-01&find\[type\]=sgv&find\[device\]\[\$ne\]=LibreLink-DB-real" \
| tee /dev/stderr \
| sed -e 's~.*"date":\([0-9]*\)[^0-9].*~\1~' -e 's~null~0~' \
> data/last-sgv-hist.time
echo ""
echo ... for scan records
LANG=C \
curl \
-s \
-H "API-SECRET: ${SECRETSHA1}" \
-H 'Accept: */*' \
-H 'Content-Type: application/json' \
"https://${SERVER}:${PORT}/api/v1/entries.json?count=1&x=`date +%s`&find\[dateString\]\[\$gte\]=2020-01-01&find\[type\]=sgv&find\[device\]=LibreLink-DB-real" \
| tee /dev/stderr \
| sed -e 's~.*"date":\([0-9]*\)[^0-9].*~\1~' -e 's~null~0~' \
> data/last-sgv-real.time
echo ""
# FIXME: handle empty result
exit