From 9469ac631ceafde9ce3f2aa56008dff8b70d852f Mon Sep 17 00:00:00 2001 From: Tzachi Dar Date: Sun, 18 Dec 2022 23:20:33 +0200 Subject: [PATCH] Use compression for operations that go to nightscout. --- bin/ns-upload-entries.sh | 2 +- bin/ns-upload.sh | 4 ++-- bin/oref0-get-ns-entries.js | 2 ++ bin/oref0-pushover.sh | 12 ++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bin/ns-upload-entries.sh b/bin/ns-upload-entries.sh index e63bf234e..43be261a0 100755 --- a/bin/ns-upload-entries.sh +++ b/bin/ns-upload-entries.sh @@ -28,7 +28,7 @@ fi # requires API_SECRET and NIGHTSCOUT_HOST to be set in calling environment (i.e. in crontab) ( -curl -m 30 -s -X POST --data-binary @${ENTRIES} \ +curl --compressed -m 30 -s -X POST --data-binary @${ENTRIES} \ ${API_SECRET_HEADER} -H "content-type: application/json" \ ${REST_ENDPOINT} ) && ( test -n "${OUTPUT}" && touch ${OUTPUT} ; logger "Uploaded ${ENTRIES} to ${NIGHTSCOUT_HOST}" ) || logger "Unable to upload to ${NIGHTSCOUT_HOST}" diff --git a/bin/ns-upload.sh b/bin/ns-upload.sh index b70adb734..010292359 100755 --- a/bin/ns-upload.sh +++ b/bin/ns-upload.sh @@ -38,13 +38,13 @@ fi if [[ "${API_SECRET,,}" =~ "token=" ]]; then REST_ENDPOINT="${REST_ENDPOINT}?${API_SECRET}" (test "$ENTRIES" != "-" && cat $ENTRIES || cat )| ( - curl -m 30 -s -X POST --data-binary @- \ + curl --compressed -m 30 -s -X POST --data-binary @- \ -H "content-type: application/json" \ $REST_ENDPOINT ) && ( test -n "$OUTPUT" && touch $OUTPUT ; logger "Uploaded $ENTRIES to $NIGHTSCOUT_HOST" ) || ( logger "Unable to upload to $NIGHTSCOUT_HOST"; exit 2 ) else (test "$ENTRIES" != "-" && cat $ENTRIES || cat )| ( - curl -m 30 -s -X POST --data-binary @- \ + curl --compressed -m 30 -s -X POST --data-binary @- \ -H "API-SECRET: $API_SECRET" \ -H "content-type: application/json" \ $REST_ENDPOINT diff --git a/bin/oref0-get-ns-entries.js b/bin/oref0-get-ns-entries.js index 6e855fec8..4932aac31 100755 --- a/bin/oref0-get-ns-entries.js +++ b/bin/oref0-get-ns-entries.js @@ -180,12 +180,14 @@ var oref0_get_ns_engtires = function oref0_get_ns_engtires(argv_params, print_ca headers["If-Modified-Since"] = lastDate.toISOString(); } + headers["User-Agent"] = 'openaps'; var uri = nsurl + '/api/v1/entries/sgv.json?count=' + records + tokenAuth; var options = { uri: uri , json: true , timeout: 90000 , headers: headers + , gzip : true }; request(options, function(error, res, data) { diff --git a/bin/oref0-pushover.sh b/bin/oref0-pushover.sh index d31859870..5820b39c6 100755 --- a/bin/oref0-pushover.sh +++ b/bin/oref0-pushover.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env bash source $(dirname $0)/oref0-bash-common-functions.sh || (echo "ERROR: Failed to run oref0-bash-common-functions.sh. Is oref0 correctly installed?"; exit 1) @@ -87,7 +87,7 @@ fi CURL_AUTH='-H api-secret:'${API_SECRET} fi - if snooze=$(curl -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="carbsReq") | select(.date>'$(date +%s -d "10 minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then + if snooze=$(curl --compressed -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="carbsReq") | select(.date>'$(date +%s -d "10 minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then #echo $snooze #echo date -Is -d @$snooze; echo touch -d $(date -Is -d @$snooze) monitor/pushover-sent @@ -107,7 +107,7 @@ elif [[ $ONLYFOR =~ "insulin" ]] && ! cat $FILE | egrep "maxBolus" > /dev/null; elif file_is_recent monitor/pushover-sent $SNOOZE; then echo -n "Last pushover sent less than $SNOOZE minutes ago. " else - curl -s -F token=$TOKEN -F user=$USER $SOUND_OPTION -F priority=$PRIORITY $PRIORITY_OPTIONS -F "message=$(jq -c "{bg, tick, carbsReq, insulinReq, reason}|del(.[] | nulls)" $FILE) - $(hostname)" https://api.pushover.net/1/messages.json | jq .status| grep 1 >/dev/null && touch monitor/pushover-sent && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"carbsReq"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "carbsReq pushover sent." + curl ---compressed s -F token=$TOKEN -F user=$USER $SOUND_OPTION -F priority=$PRIORITY $PRIORITY_OPTIONS -F "message=$(jq -c "{bg, tick, carbsReq, insulinReq, reason}|del(.[] | nulls)" $FILE) - $(hostname)" https://api.pushover.net/1/messages.json | jq .status| grep 1 >/dev/null && touch monitor/pushover-sent && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"carbsReq"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "carbsReq pushover sent." echo fi @@ -152,7 +152,7 @@ else touch $GLANCES && touch -r $GLANCES -d '-60 mins' $GLANCES fi - if snooze=$(curl -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="glance") | select(.date>'$(date +%s -d "$glanceDelay minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then + if snooze=$(curl --compressed -s ${CURL_AUTH} ${URL} | jq '.[] | select(.snooze=="glance") | select(.date>'$(date +%s -d "$glanceDelay minutes ago")')' | jq -s .[0].date | noquotes | grep -v null); then #echo $snooze #echo date -Is -d @$snooze; echo touch -d $(date -Is -d @$snooze) $GLANCES @@ -195,7 +195,7 @@ else subtext="$carbsMsg${rate}U/h ${duration}m" # echo "pushover glance text=${text} subtext=${subtext} delta=${delta} title=${title} battery percent=${battery}" - curl -s -F "token=$TOKEN" -F "user=$USER" -F "text=${text}" -F "subtext=${subtext}" -F "count=$bgNow" -F "percent=${battery}" -F "title=${title}" https://api.pushover.net/1/glances.json | jq .status| grep 1 >/dev/null && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"glance"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "Glance uploaded and snoozed" + curl --compressed -s -F "token=$TOKEN" -F "user=$USER" -F "text=${text}" -F "subtext=${subtext}" -F "count=$bgNow" -F "percent=${battery}" -F "title=${title}" https://api.pushover.net/1/glances.json | jq .status| grep 1 >/dev/null && echo '{"date":'$(epochtime_now)',"device":"openaps://'$(hostname)'","snooze":"glance"}' > /tmp/snooze.json && ns-upload $NIGHTSCOUT_HOST $API_SECRET devicestatus.json /tmp/snooze.json >/dev/null && echo "Glance uploaded and snoozed" touch $GLANCES else echo -n "Pushover glance last updated less than $glanceDelay minutes ago @ " @@ -223,7 +223,7 @@ if ! [ -z "$MAKER_KEY" ] && [[ "$MAKER_KEY" != "null" ]] && cat $FILE | egrep "a echo $values > $ifttt - curl --request POST \ + curl --compressed --request POST \ --header 'Content-Type: application/json' \ -d @$ifttt \ https://maker.ifttt.com/trigger/carbs-required/with/key/${key} && touch monitor/ifttt-sent