Skip to content

Instantly share code, notes, and snippets.

@devoncrouse
Created September 4, 2017 01:28
Show Gist options
  • Save devoncrouse/d363ff706580b8afea1a920aafd1ed67 to your computer and use it in GitHub Desktop.
Save devoncrouse/d363ff706580b8afea1a920aafd1ed67 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# ./getPitchers.sh <apiKey>
CAMS=$(curl -s -L -X GET \
https://developer-api.nest.com/devices/cameras/ \
-H "authorization: Bearer ${1}" \
-H 'cache-control: no-cache' \
-H 'content-type: application/json')
CAMS_CSV=$(echo ${CAMS} | jq -r '. | map([(.name | gsub(" "; "") | ascii_downcase), .snapshot_url, .last_event.image_url, .last_event.animated_image_url] | join(",")) | join("\n")')
for line in $(echo ${CAMS_CSV}) ; do
device=$(echo ${line} | cut -d"," -f1)
echo "Retrieving images for device: ${device}..."
snapshotUrl=$(echo ${line} | cut -d"," -f2)
if [[ ! -z ${snapshotUrl} ]]; then
curl -s -o snapshot_${device}_$(date +%H).jpg -L -X GET ${snapshotUrl}
fi
eventUrl=$(echo ${line} | cut -d"," -f3)
if [[ ! -z ${eventUrl} ]]; then
curl -s -o event_${device}_$(date +%H).jpg -L -X GET ${eventUrl}
fi
gifUrl=$(echo ${line} | cut -d"," -f4)
if [[ ! -z ${gifUrl} ]]; then
curl -s -o gif_${device}_$(date +%H).jpg -L -X GET ${gifUrl}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment