Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 79 additions & 5 deletions bin/nightscout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,93 @@ $self <cmd>
* latest-openaps-treatment
* cull-latest-openaps-treatments

* ns-get
* ns-upload
* ns-dedupe-treatments
* ns-status
* ns-upload-entries
* get
* upload
* dedupe-treatments
* status
* upload-entries
* autoconfigure-device-crud

EOF
}

function setup_help ( ) {

cat <<EOF
$self autoconfigure-device-crud <NIGHTSCOUT_HOST> <API_SECRET>

sets up:
openaps use ns shell get entries.json 'count=10'
openaps use ns shell upload treatments.json recently/combined-treatments.json
EOF
}

function ns_help ( ) {
cat <<EOF
TODO: improve help
openaps use ns shell get entries.json 'count=10'
openaps use ns shell upload treatments.json recently/combined-treatments.json
EOF
}
case $NAME in
latest-openaps-treatment)
ns-get treatments.json'?find[enteredBy]=/openaps:\/\//&count=1' $* | json 0
;;
ns)
NIGHTSCOUT_HOST=$1
API_SECRET=$2
OP=$3
shift
shift
shift

case $OP in
-h|--help|help)
ns_help
exit 0
;;
get)
exec ns-get host $NIGHTSCOUT_HOST $*
;;
upload)
exec ns-upload $NIGHTSCOUT_HOST $API_SECRET $*
;;
*)
echo "Unknown request:" $OP
ns_help
exit 1;
;;
esac

;;
hash-api-secret)
if [[ -z "$1" ]] ; then
echo "Missing plain Nightscout passphrase".
echo "Usage: $self hash-api-secret 'myverylongsecret'".
exit 1;
fi
API_SECRET=$(echo -n $1 | sha1sum | cut -d ' ' -f 1 | tr -d "\n")
echo $API_SECRET
;;
autoconfigure-device-crud)
NIGHTSCOUT_HOST=$1
PLAIN_NS_SECRET=$2
API_SECRET=$($self hash-api-secret $2)
case $1 in
help|-h|--help)
setup_help
exit 0
;;
esac
# openaps device add ns-get host
test -z "$NIGHTSCOUT_HOST" && setup_help && exit 1;
test -z "$API_SECRET" && setup_help && exit 1;
openaps device add ns process --require "oper remote input" nightscout ns "NIGHTSCOUT_HOST" "API_SECRET"
openaps device show ns --json | json \
| json -e "this.extra.args = this.extra.args.replace(' NIGHTSCOUT_HOST ', ' $NIGHTSCOUT_HOST ')" \
| json -e "this.extra.args = this.extra.args.replace(' API_SECRET', ' $API_SECRET')" \
| openaps import
;;
cull-latest-openaps-treatments)
INPUT=$1
MODEL=$2
Expand Down
2 changes: 2 additions & 0 deletions bin/ns-get.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ EOF
QUERY=${4}
OUTPUT=${5-/dev/fd/1}
REPORT_ENDPOINT=$NIGHTSCOUT_HOST/api/v1/${REPORT}'?'${QUERY}
test -z "$NIGHTSCOUT_HOST" && usage && exit 1;
curl -g -s $REPORT_ENDPOINT | json

;;
type)
Expand Down
6 changes: 6 additions & 0 deletions bin/ns-upload.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ EOF
fi
# requires API_SECRET and NIGHTSCOUT_HOST to be set in calling environment
# (i.e. in crontab)
if [[ "$ENTRIES" != "-" ]] ; then
if [[ ! -f $ENTRIES ]] ; then
echo "Input file $ENTRIES" does not exist.
exit 1;
fi
fi
(test "$ENTRIES" != "-" && cat $ENTRIES || cat )| (
curl -m 30 -s -X POST --data-binary @- \
-H "API-SECRET: $API_SECRET" \
Expand Down
37 changes: 37 additions & 0 deletions bin/oref0-copy-fresher
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
self=$(basename $0)
WITHIN=0

function usage ( ) {
cat <<EOF
$self [--since <seconds|0>] <file> [<file>...]
cat files mentioned.
If --since seconds is specified, the file will only be cat'd if the files last
modification occurred within <seconds>.
Default <seconds> is 0, it will cat all files.
EOF
}
case $1 in
--help|-h|help)
usage
exit 0
;;
--since)
shift
WITHIN=$1
shift
;;
esac


for file in $* ; do
if [[ -f $file && ($WITHIN -eq 0 || $(expr $(date +%s) - $(date +%s -r $file)) -lt $WITHIN) ]] ; then
cat $file
fi
done


# 2783 test $(expr $(date +%s) - $(date +%s -r openaps.ini )) -gt 1000 && echo "OK" || echo "NOT"
# 2784 test $(expr $(date +%s) - $(date +%s -r openaps.ini )) -gt 1000000 && echo "OK" || echo "NOT"
# 2785 history | tail -n 3 > blah

27 changes: 27 additions & 0 deletions bin/oref0-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env node



var argv = require('yargs')
.usage("$0 <cmd> <type> [args]")
/*
.option('', {
})
*/
.command('mint <type>', 'generate template for import', require('oref0/lib/templates/'))
// .choices('type', ['devices', 'reports', 'alias', '*'])
/*
.command('devices', 'generate common device loops', function (yargs) {
return yargs.option('b', {
alias: 'bar'
});
})
*/
.help('help')
.alias('h', 'help')
.completion( )
.strict( )
.argv
;

// console.log('after', argv);
Loading