-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdb-to-dump
executable file
·62 lines (55 loc) · 1.59 KB
/
db-to-dump
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
58
59
60
61
62
#!/bin/bash
cd `dirname $0`
# OS independent date conversion - this also works on Mac
ts2tab() {
ruby -e '
require "time"
$stdin.read.each_line { |line|
if line =~ /(\d+)\s+(.*)/
ep = $1.to_i
val = $2
ts = Time.at(ep/1000).utc
dt = ts.iso8601
printf("%s\t%d\t%s\n", dt, ep, val)
end
}'
}
DB=tmp/apps/com.freestylelibre.app.de/f/sas.db
if ! which ruby >/dev/null
then
echo "\"ruby\" not found - required for date conversion"
exit 98
fi
if ! which sqlite3 >/dev/null
then
echo "\"sqlite3\" not found - required for database dump"
exit 98
fi
if [ ! -f ${DB} ]
then
echo "database not found - did you extract it from the phome?"
exit 97
fi
# sas database contains sensor information
mkdir -p data
sqlite3 -column -noheader ${DB} \
'select sensorStartTimestampUTC, serialNumber from sensors;' \
| ts2tab \
> data/sensors.dump
printf "%6d %s\n" `cat data/sensors.dump | wc -l` "sensor serial number records dumped"
sqlite3 -column -noheader ${DB} \
'select timestampUTC, glucoseValue from currentReadings;' \
| ts2tab \
> data/sg-curr.dump
printf "%6d %s\n" `cat data/sg-curr.dump | wc -l` "currentReadings (1-min) records dumped"
sqlite3 -column -noheader ${DB} \
'select timestampUTC, glucoseValue from historicReadings;' \
| ts2tab \
> data/sg-hist.dump
printf "%6d %s\n" `cat data/sg-hist.dump | wc -l` "historicReadings (15-min) records dumped"
sqlite3 -column -noheader ${DB} \
'select timestampUTC, glucoseValue from realTimeReadings;' \
| ts2tab \
> data/sg-real.dump
printf "%6d %s\n" `cat data/sg-real.dump | wc -l` "realTimeReadings (scans) records dumped"
exit 0